﻿using System;
using System.Collections.Generic;
using System.Linq;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.GameMenus;
using TaleWorlds.CampaignSystem.GameState;
using TaleWorlds.CampaignSystem.Inventory;
using TaleWorlds.CampaignSystem.Map;
using TaleWorlds.CampaignSystem.MapEvents;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Roster;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.CampaignSystem.Siege;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.LinQuick;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.Encounters
{
	// Token: 0x02000291 RID: 657
	public class PlayerEncounter
	{
		// Token: 0x060023BE RID: 9150 RVA: 0x00096E68 File Offset: 0x00095068
		internal static void AutoGeneratedStaticCollectObjectsPlayerEncounter(object o, List<object> collectedObjects)
		{
			((PlayerEncounter)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
		}

		// Token: 0x060023BF RID: 9151 RVA: 0x00096E78 File Offset: 0x00095078
		protected virtual void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
		{
			collectedObjects.Add(this._campaignBattleResult);
			collectedObjects.Add(this._mapEvent);
			collectedObjects.Add(this._encounteredParty);
			collectedObjects.Add(this._attackerParty);
			collectedObjects.Add(this._defenderParty);
			collectedObjects.Add(this._helpedHeroes);
			collectedObjects.Add(this._capturedHeroes);
			collectedObjects.Add(this._freedHeroes);
			collectedObjects.Add(this._alternativeRosterToReceiveLootItems);
			collectedObjects.Add(this._alternativeRosterToReceiveLootPrisoners);
			collectedObjects.Add(this._alternativeRosterToReceiveLootMembers);
			collectedObjects.Add(this.EncounterSettlementAux);
		}

		// Token: 0x060023C0 RID: 9152 RVA: 0x00096F15 File Offset: 0x00095115
		internal static object AutoGeneratedGetMemberValueOpponentSide(object o)
		{
			return ((PlayerEncounter)o).OpponentSide;
		}

		// Token: 0x060023C1 RID: 9153 RVA: 0x00096F27 File Offset: 0x00095127
		internal static object AutoGeneratedGetMemberValuePlayerSide(object o)
		{
			return ((PlayerEncounter)o).PlayerSide;
		}

		// Token: 0x060023C2 RID: 9154 RVA: 0x00096F39 File Offset: 0x00095139
		internal static object AutoGeneratedGetMemberValueIsJoinedBattle(object o)
		{
			return ((PlayerEncounter)o).IsJoinedBattle;
		}

		// Token: 0x060023C3 RID: 9155 RVA: 0x00096F4B File Offset: 0x0009514B
		internal static object AutoGeneratedGetMemberValueEncounterSettlementAux(object o)
		{
			return ((PlayerEncounter)o).EncounterSettlementAux;
		}

		// Token: 0x060023C4 RID: 9156 RVA: 0x00096F58 File Offset: 0x00095158
		internal static object AutoGeneratedGetMemberValueIsPlayerWaiting(object o)
		{
			return ((PlayerEncounter)o).IsPlayerWaiting;
		}

		// Token: 0x060023C5 RID: 9157 RVA: 0x00096F6A File Offset: 0x0009516A
		internal static object AutoGeneratedGetMemberValueFirstInit(object o)
		{
			return ((PlayerEncounter)o).FirstInit;
		}

		// Token: 0x060023C6 RID: 9158 RVA: 0x00096F7C File Offset: 0x0009517C
		internal static object AutoGeneratedGetMemberValueIsEnemy(object o)
		{
			return ((PlayerEncounter)o).IsEnemy;
		}

		// Token: 0x060023C7 RID: 9159 RVA: 0x00096F8E File Offset: 0x0009518E
		internal static object AutoGeneratedGetMemberValuePlayerPartyInitialStrength(object o)
		{
			return ((PlayerEncounter)o).PlayerPartyInitialStrength;
		}

		// Token: 0x060023C8 RID: 9160 RVA: 0x00096FA0 File Offset: 0x000951A0
		internal static object AutoGeneratedGetMemberValuePartiesStrengthRatioBeforePlayerJoin(object o)
		{
			return ((PlayerEncounter)o).PartiesStrengthRatioBeforePlayerJoin;
		}

		// Token: 0x060023C9 RID: 9161 RVA: 0x00096FB2 File Offset: 0x000951B2
		internal static object AutoGeneratedGetMemberValueForceRaid(object o)
		{
			return ((PlayerEncounter)o).ForceRaid;
		}

		// Token: 0x060023CA RID: 9162 RVA: 0x00096FC4 File Offset: 0x000951C4
		internal static object AutoGeneratedGetMemberValueForceSallyOut(object o)
		{
			return ((PlayerEncounter)o).ForceSallyOut;
		}

		// Token: 0x060023CB RID: 9163 RVA: 0x00096FD6 File Offset: 0x000951D6
		internal static object AutoGeneratedGetMemberValueForceVolunteers(object o)
		{
			return ((PlayerEncounter)o).ForceVolunteers;
		}

		// Token: 0x060023CC RID: 9164 RVA: 0x00096FE8 File Offset: 0x000951E8
		internal static object AutoGeneratedGetMemberValueForceSupplies(object o)
		{
			return ((PlayerEncounter)o).ForceSupplies;
		}

		// Token: 0x060023CD RID: 9165 RVA: 0x00096FFA File Offset: 0x000951FA
		internal static object AutoGeneratedGetMemberValue_campaignBattleResult(object o)
		{
			return ((PlayerEncounter)o)._campaignBattleResult;
		}

		// Token: 0x060023CE RID: 9166 RVA: 0x00097007 File Offset: 0x00095207
		internal static object AutoGeneratedGetMemberValue_isSiegeInterruptedByEnemyDefection(object o)
		{
			return ((PlayerEncounter)o)._isSiegeInterruptedByEnemyDefection;
		}

		// Token: 0x060023CF RID: 9167 RVA: 0x00097019 File Offset: 0x00095219
		internal static object AutoGeneratedGetMemberValue_mapEvent(object o)
		{
			return ((PlayerEncounter)o)._mapEvent;
		}

		// Token: 0x060023D0 RID: 9168 RVA: 0x00097026 File Offset: 0x00095226
		internal static object AutoGeneratedGetMemberValue_mapEventState(object o)
		{
			return ((PlayerEncounter)o)._mapEventState;
		}

		// Token: 0x060023D1 RID: 9169 RVA: 0x00097038 File Offset: 0x00095238
		internal static object AutoGeneratedGetMemberValue_encounteredParty(object o)
		{
			return ((PlayerEncounter)o)._encounteredParty;
		}

		// Token: 0x060023D2 RID: 9170 RVA: 0x00097045 File Offset: 0x00095245
		internal static object AutoGeneratedGetMemberValue_attackerParty(object o)
		{
			return ((PlayerEncounter)o)._attackerParty;
		}

		// Token: 0x060023D3 RID: 9171 RVA: 0x00097052 File Offset: 0x00095252
		internal static object AutoGeneratedGetMemberValue_defenderParty(object o)
		{
			return ((PlayerEncounter)o)._defenderParty;
		}

		// Token: 0x060023D4 RID: 9172 RVA: 0x0009705F File Offset: 0x0009525F
		internal static object AutoGeneratedGetMemberValue_helpedHeroes(object o)
		{
			return ((PlayerEncounter)o)._helpedHeroes;
		}

		// Token: 0x060023D5 RID: 9173 RVA: 0x0009706C File Offset: 0x0009526C
		internal static object AutoGeneratedGetMemberValue_capturedHeroes(object o)
		{
			return ((PlayerEncounter)o)._capturedHeroes;
		}

		// Token: 0x060023D6 RID: 9174 RVA: 0x00097079 File Offset: 0x00095279
		internal static object AutoGeneratedGetMemberValue_freedHeroes(object o)
		{
			return ((PlayerEncounter)o)._freedHeroes;
		}

		// Token: 0x060023D7 RID: 9175 RVA: 0x00097086 File Offset: 0x00095286
		internal static object AutoGeneratedGetMemberValue_leaveEncounter(object o)
		{
			return ((PlayerEncounter)o)._leaveEncounter;
		}

		// Token: 0x060023D8 RID: 9176 RVA: 0x00097098 File Offset: 0x00095298
		internal static object AutoGeneratedGetMemberValue_playerSurrender(object o)
		{
			return ((PlayerEncounter)o)._playerSurrender;
		}

		// Token: 0x060023D9 RID: 9177 RVA: 0x000970AA File Offset: 0x000952AA
		internal static object AutoGeneratedGetMemberValue_enemySurrender(object o)
		{
			return ((PlayerEncounter)o)._enemySurrender;
		}

		// Token: 0x060023DA RID: 9178 RVA: 0x000970BC File Offset: 0x000952BC
		internal static object AutoGeneratedGetMemberValue_battleChallenge(object o)
		{
			return ((PlayerEncounter)o)._battleChallenge;
		}

		// Token: 0x060023DB RID: 9179 RVA: 0x000970CE File Offset: 0x000952CE
		internal static object AutoGeneratedGetMemberValue_meetingDone(object o)
		{
			return ((PlayerEncounter)o)._meetingDone;
		}

		// Token: 0x060023DC RID: 9180 RVA: 0x000970E0 File Offset: 0x000952E0
		internal static object AutoGeneratedGetMemberValue_stateHandled(object o)
		{
			return ((PlayerEncounter)o)._stateHandled;
		}

		// Token: 0x060023DD RID: 9181 RVA: 0x000970F2 File Offset: 0x000952F2
		internal static object AutoGeneratedGetMemberValue_alternativeRosterToReceiveLootItems(object o)
		{
			return ((PlayerEncounter)o)._alternativeRosterToReceiveLootItems;
		}

		// Token: 0x060023DE RID: 9182 RVA: 0x000970FF File Offset: 0x000952FF
		internal static object AutoGeneratedGetMemberValue_alternativeRosterToReceiveLootPrisoners(object o)
		{
			return ((PlayerEncounter)o)._alternativeRosterToReceiveLootPrisoners;
		}

		// Token: 0x060023DF RID: 9183 RVA: 0x0009710C File Offset: 0x0009530C
		internal static object AutoGeneratedGetMemberValue_alternativeRosterToReceiveLootMembers(object o)
		{
			return ((PlayerEncounter)o)._alternativeRosterToReceiveLootMembers;
		}

		// Token: 0x060023E0 RID: 9184 RVA: 0x00097119 File Offset: 0x00095319
		internal static object AutoGeneratedGetMemberValue_doesBattleContinue(object o)
		{
			return ((PlayerEncounter)o)._doesBattleContinue;
		}

		// Token: 0x060023E1 RID: 9185 RVA: 0x0009712B File Offset: 0x0009532B
		internal static object AutoGeneratedGetMemberValue_isSallyOutAmbush(object o)
		{
			return ((PlayerEncounter)o)._isSallyOutAmbush;
		}

		// Token: 0x170008E6 RID: 2278
		// (get) Token: 0x060023E2 RID: 9186 RVA: 0x0009713D File Offset: 0x0009533D
		public static PlayerEncounter Current
		{
			get
			{
				return Campaign.Current.PlayerEncounter;
			}
		}

		// Token: 0x170008E7 RID: 2279
		// (get) Token: 0x060023E3 RID: 9187 RVA: 0x00097149 File Offset: 0x00095349
		// (set) Token: 0x060023E4 RID: 9188 RVA: 0x00097155 File Offset: 0x00095355
		public static LocationEncounter LocationEncounter
		{
			get
			{
				return Campaign.Current.LocationEncounter;
			}
			set
			{
				Campaign.Current.LocationEncounter = value;
			}
		}

		// Token: 0x170008E8 RID: 2280
		// (get) Token: 0x060023E5 RID: 9189 RVA: 0x00097162 File Offset: 0x00095362
		public static MapEvent Battle
		{
			get
			{
				if (PlayerEncounter.Current == null)
				{
					return null;
				}
				return PlayerEncounter.Current._mapEvent;
			}
		}

		// Token: 0x170008E9 RID: 2281
		// (get) Token: 0x060023E6 RID: 9190 RVA: 0x00097177 File Offset: 0x00095377
		public static PartyBase EncounteredParty
		{
			get
			{
				if (PlayerEncounter.Current != null)
				{
					return PlayerEncounter.Current._encounteredParty;
				}
				return null;
			}
		}

		// Token: 0x170008EA RID: 2282
		// (get) Token: 0x060023E7 RID: 9191 RVA: 0x0009718C File Offset: 0x0009538C
		public static MobileParty EncounteredMobileParty
		{
			get
			{
				PartyBase encounteredParty = PlayerEncounter.EncounteredParty;
				if (encounteredParty == null)
				{
					return null;
				}
				return encounteredParty.MobileParty;
			}
		}

		// Token: 0x170008EB RID: 2283
		// (get) Token: 0x060023E8 RID: 9192 RVA: 0x000971A0 File Offset: 0x000953A0
		public static MapEvent EncounteredBattle
		{
			get
			{
				if (PlayerEncounter.Current._encounteredParty.MapEvent != null)
				{
					return PlayerEncounter.Current._encounteredParty.MapEvent;
				}
				if (PlayerEncounter.Current._encounteredParty.IsSettlement)
				{
					SiegeEvent siegeEvent = PlayerEncounter.Current._encounteredParty.SiegeEvent;
					if (((siegeEvent != null) ? siegeEvent.BesiegerCamp.LeaderParty.MapEvent : null) != null)
					{
						return PlayerEncounter.Current._encounteredParty.SiegeEvent.BesiegerCamp.LeaderParty.MapEvent;
					}
				}
				return null;
			}
		}

		// Token: 0x170008EC RID: 2284
		// (get) Token: 0x060023E9 RID: 9193 RVA: 0x00097226 File Offset: 0x00095426
		public static BattleState BattleState
		{
			get
			{
				return PlayerEncounter.Current._mapEvent.BattleState;
			}
		}

		// Token: 0x170008ED RID: 2285
		// (get) Token: 0x060023EA RID: 9194 RVA: 0x00097237 File Offset: 0x00095437
		public static BattleSideEnum WinningSide
		{
			get
			{
				return PlayerEncounter.Current._mapEvent.WinningSide;
			}
		}

		// Token: 0x170008EE RID: 2286
		// (get) Token: 0x060023EB RID: 9195 RVA: 0x00097248 File Offset: 0x00095448
		// (set) Token: 0x060023EC RID: 9196 RVA: 0x00097254 File Offset: 0x00095454
		public static bool BattleChallenge
		{
			get
			{
				return PlayerEncounter.Current._battleChallenge;
			}
			set
			{
				PlayerEncounter.Current._battleChallenge = value;
			}
		}

		// Token: 0x170008EF RID: 2287
		// (get) Token: 0x060023ED RID: 9197 RVA: 0x00097261 File Offset: 0x00095461
		public static bool PlayerIsDefender
		{
			get
			{
				return PlayerEncounter.Current.PlayerSide == BattleSideEnum.Defender;
			}
		}

		// Token: 0x170008F0 RID: 2288
		// (get) Token: 0x060023EE RID: 9198 RVA: 0x00097270 File Offset: 0x00095470
		public static bool PlayerIsAttacker
		{
			get
			{
				return PlayerEncounter.Current.PlayerSide == BattleSideEnum.Attacker;
			}
		}

		// Token: 0x170008F1 RID: 2289
		// (get) Token: 0x060023EF RID: 9199 RVA: 0x0009727F File Offset: 0x0009547F
		// (set) Token: 0x060023F0 RID: 9200 RVA: 0x0009728B File Offset: 0x0009548B
		public static bool LeaveEncounter
		{
			get
			{
				return PlayerEncounter.Current._leaveEncounter;
			}
			set
			{
				PlayerEncounter.Current._leaveEncounter = value;
			}
		}

		// Token: 0x170008F2 RID: 2290
		// (get) Token: 0x060023F1 RID: 9201 RVA: 0x00097298 File Offset: 0x00095498
		public static bool MeetingDone
		{
			get
			{
				return PlayerEncounter.Current._meetingDone;
			}
		}

		// Token: 0x170008F3 RID: 2291
		// (get) Token: 0x060023F2 RID: 9202 RVA: 0x000972A4 File Offset: 0x000954A4
		// (set) Token: 0x060023F3 RID: 9203 RVA: 0x000972B0 File Offset: 0x000954B0
		public static bool PlayerSurrender
		{
			get
			{
				return PlayerEncounter.Current._playerSurrender;
			}
			set
			{
				if (value)
				{
					PlayerEncounter.Current.PlayerSurrenderInternal();
				}
			}
		}

		// Token: 0x170008F4 RID: 2292
		// (get) Token: 0x060023F4 RID: 9204 RVA: 0x000972BF File Offset: 0x000954BF
		// (set) Token: 0x060023F5 RID: 9205 RVA: 0x000972CB File Offset: 0x000954CB
		public static bool EnemySurrender
		{
			get
			{
				return PlayerEncounter.Current._enemySurrender;
			}
			set
			{
				if (value)
				{
					PlayerEncounter.Current.EnemySurrenderInternal();
				}
			}
		}

		// Token: 0x170008F5 RID: 2293
		// (get) Token: 0x060023F6 RID: 9206 RVA: 0x000972DA File Offset: 0x000954DA
		public static bool IsActive
		{
			get
			{
				return PlayerEncounter.Current != null;
			}
		}

		// Token: 0x170008F6 RID: 2294
		// (get) Token: 0x060023F7 RID: 9207 RVA: 0x000972E4 File Offset: 0x000954E4
		// (set) Token: 0x060023F8 RID: 9208 RVA: 0x000972EC File Offset: 0x000954EC
		[SaveableProperty(2)]
		public BattleSideEnum OpponentSide { get; private set; }

		// Token: 0x170008F7 RID: 2295
		// (get) Token: 0x060023F9 RID: 9209 RVA: 0x000972F5 File Offset: 0x000954F5
		// (set) Token: 0x060023FA RID: 9210 RVA: 0x000972FD File Offset: 0x000954FD
		[SaveableProperty(3)]
		public BattleSideEnum PlayerSide { get; private set; }

		// Token: 0x170008F8 RID: 2296
		// (get) Token: 0x060023FB RID: 9211 RVA: 0x00097306 File Offset: 0x00095506
		// (set) Token: 0x060023FC RID: 9212 RVA: 0x0009730E File Offset: 0x0009550E
		[SaveableProperty(6)]
		public bool IsJoinedBattle { get; private set; }

		// Token: 0x170008F9 RID: 2297
		// (get) Token: 0x060023FD RID: 9213 RVA: 0x00097317 File Offset: 0x00095517
		public static bool InsideSettlement
		{
			get
			{
				return MobileParty.MainParty.IsActive && MobileParty.MainParty.CurrentSettlement != null;
			}
		}

		// Token: 0x170008FA RID: 2298
		// (get) Token: 0x060023FE RID: 9214 RVA: 0x00097334 File Offset: 0x00095534
		// (set) Token: 0x060023FF RID: 9215 RVA: 0x00097340 File Offset: 0x00095540
		public static CampaignBattleResult CampaignBattleResult
		{
			get
			{
				return PlayerEncounter.Current._campaignBattleResult;
			}
			set
			{
				PlayerEncounter.Current._campaignBattleResult = value;
			}
		}

		// Token: 0x170008FB RID: 2299
		// (get) Token: 0x06002400 RID: 9216 RVA: 0x0009734D File Offset: 0x0009554D
		public static BattleSimulation CurrentBattleSimulation
		{
			get
			{
				if (PlayerEncounter.Current == null)
				{
					return null;
				}
				return PlayerEncounter.Current.BattleSimulation;
			}
		}

		// Token: 0x170008FC RID: 2300
		// (get) Token: 0x06002401 RID: 9217 RVA: 0x00097362 File Offset: 0x00095562
		// (set) Token: 0x06002402 RID: 9218 RVA: 0x0009736A File Offset: 0x0009556A
		public PlayerEncounterState EncounterState
		{
			get
			{
				return this._mapEventState;
			}
			private set
			{
				this._mapEventState = value;
			}
		}

		// Token: 0x170008FD RID: 2301
		// (get) Token: 0x06002403 RID: 9219 RVA: 0x00097373 File Offset: 0x00095573
		public ItemRoster RosterToReceiveLootItems
		{
			get
			{
				if (this._alternativeRosterToReceiveLootItems == null)
				{
					this._alternativeRosterToReceiveLootItems = new ItemRoster();
				}
				return this._alternativeRosterToReceiveLootItems;
			}
		}

		// Token: 0x170008FE RID: 2302
		// (get) Token: 0x06002404 RID: 9220 RVA: 0x0009738E File Offset: 0x0009558E
		public TroopRoster RosterToReceiveLootPrisoners
		{
			get
			{
				if (this._alternativeRosterToReceiveLootPrisoners == null)
				{
					this._alternativeRosterToReceiveLootPrisoners = TroopRoster.CreateDummyTroopRoster();
				}
				return this._alternativeRosterToReceiveLootPrisoners;
			}
		}

		// Token: 0x170008FF RID: 2303
		// (get) Token: 0x06002405 RID: 9221 RVA: 0x000973AF File Offset: 0x000955AF
		public TroopRoster RosterToReceiveLootMembers
		{
			get
			{
				if (this._alternativeRosterToReceiveLootMembers == null)
				{
					this._alternativeRosterToReceiveLootMembers = TroopRoster.CreateDummyTroopRoster();
				}
				return this._alternativeRosterToReceiveLootMembers;
			}
		}

		// Token: 0x17000900 RID: 2304
		// (get) Token: 0x06002406 RID: 9222 RVA: 0x000973D0 File Offset: 0x000955D0
		public static Settlement EncounterSettlement
		{
			get
			{
				PlayerEncounter playerEncounter = PlayerEncounter.Current;
				if (playerEncounter == null)
				{
					return null;
				}
				return playerEncounter.EncounterSettlementAux;
			}
		}

		// Token: 0x17000901 RID: 2305
		// (get) Token: 0x06002407 RID: 9223 RVA: 0x000973E2 File Offset: 0x000955E2
		// (set) Token: 0x06002408 RID: 9224 RVA: 0x000973EA File Offset: 0x000955EA
		[SaveableProperty(28)]
		public Settlement EncounterSettlementAux { get; private set; }

		// Token: 0x17000902 RID: 2306
		// (get) Token: 0x06002409 RID: 9225 RVA: 0x000973F3 File Offset: 0x000955F3
		// (set) Token: 0x0600240A RID: 9226 RVA: 0x000973FB File Offset: 0x000955FB
		[SaveableProperty(50)]
		public bool IsPlayerWaiting { get; set; }

		// Token: 0x0600240B RID: 9227 RVA: 0x00097404 File Offset: 0x00095604
		private PlayerEncounter()
		{
		}

		// Token: 0x0600240C RID: 9228 RVA: 0x00097414 File Offset: 0x00095614
		public void OnLoad()
		{
			if (PlayerEncounter.InsideSettlement && PlayerEncounter.Battle == null)
			{
				PlayerEncounter.CreateLocationEncounter(MobileParty.MainParty.CurrentSettlement);
				return;
			}
			if (PlayerEncounter.Current != null && PlayerEncounter.EncounterSettlement != null && PlayerEncounter.EncounterSettlement.IsVillage && PlayerEncounter.Current.IsPlayerWaiting)
			{
				PlayerEncounter.CreateLocationEncounter(this.EncounterSettlementAux);
			}
		}

		// Token: 0x0600240D RID: 9229 RVA: 0x00097470 File Offset: 0x00095670
		public static void RestartPlayerEncounter(PartyBase defenderParty, PartyBase attackerParty, bool forcePlayerOutFromSettlement = true)
		{
			if (PlayerEncounter.Current != null)
			{
				PlayerEncounter.Finish(forcePlayerOutFromSettlement);
			}
			PlayerEncounter.Start();
			PlayerEncounter.Current.SetupFields(attackerParty, defenderParty);
		}

		// Token: 0x0600240E RID: 9230 RVA: 0x00097490 File Offset: 0x00095690
		internal static void SimulateBattle()
		{
			PlayerEncounter.Battle.SimulatePlayerEncounterBattle();
		}

		// Token: 0x0600240F RID: 9231 RVA: 0x0009749C File Offset: 0x0009569C
		internal void Init(PartyBase attackerParty, PartyBase defenderParty, Settlement settlement = null)
		{
			this.EncounterSettlementAux = ((settlement != null) ? settlement : (defenderParty.IsSettlement ? defenderParty.Settlement : attackerParty.Settlement));
			PlayerEncounter.EncounteredPartySurrendered = false;
			this.PlayerPartyInitialStrength = PartyBase.MainParty.TotalStrength;
			this.SetupFields(attackerParty, defenderParty);
			if (defenderParty.MapEvent != null && attackerParty != MobileParty.MainParty.Party && defenderParty != MobileParty.MainParty.Party)
			{
				this._mapEvent = defenderParty.MapEvent;
				if (this._mapEvent.CanPartyJoinBattle(PartyBase.MainParty, BattleSideEnum.Defender))
				{
					MobileParty.MainParty.Party.MapEventSide = this._mapEvent.DefenderSide;
				}
				else if (this._mapEvent.CanPartyJoinBattle(PartyBase.MainParty, BattleSideEnum.Attacker))
				{
					MobileParty.MainParty.Party.MapEventSide = this._mapEvent.AttackerSide;
				}
			}
			bool flag = false;
			bool flag2 = false;
			string encounterMenu = Campaign.Current.Models.EncounterGameMenuModel.GetEncounterMenu(attackerParty, defenderParty, out flag2, out flag);
			if (!string.IsNullOrEmpty(encounterMenu))
			{
				if (flag2)
				{
					PlayerEncounter.StartBattle();
				}
				if (flag)
				{
					if (MobileParty.MainParty.MapEvent == null)
					{
						if (defenderParty.MapEvent != null)
						{
							if (defenderParty.MapEvent.CanPartyJoinBattle(PartyBase.MainParty, BattleSideEnum.Attacker))
							{
								PlayerEncounter.JoinBattle(BattleSideEnum.Attacker);
							}
							else if (defenderParty.MapEvent.CanPartyJoinBattle(PartyBase.MainParty, BattleSideEnum.Defender))
							{
								PlayerEncounter.JoinBattle(BattleSideEnum.Defender);
							}
							else
							{
								Debug.FailedAssert("false", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\Encounters\\PlayerEncounter.cs", "Init", 461);
							}
						}
						else
						{
							Debug.FailedAssert("If there is no map event we should create one in order to join battle", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\Encounters\\PlayerEncounter.cs", "Init", 466);
						}
					}
					this.CheckNearbyPartiesToJoinPlayerMapEvent();
				}
				if (attackerParty == PartyBase.MainParty && defenderParty.IsSettlement && !defenderParty.Settlement.IsUnderRaid && !defenderParty.Settlement.IsUnderSiege)
				{
					PlayerEncounter.EnterSettlement();
				}
				GameMenu.ActivateGameMenu(encounterMenu);
				return;
			}
			if (attackerParty == PartyBase.MainParty && defenderParty.IsSettlement && !defenderParty.Settlement.IsUnderRaid && !defenderParty.Settlement.IsUnderSiege)
			{
				PlayerEncounter.EnterSettlement();
			}
		}

		// Token: 0x06002410 RID: 9232 RVA: 0x00097698 File Offset: 0x00095898
		public static void Init()
		{
			if (PlayerEncounter.Current == null)
			{
				PlayerEncounter.Start();
			}
			PlayerEncounter.Current.InitAux();
		}

		// Token: 0x06002411 RID: 9233 RVA: 0x000976B0 File Offset: 0x000958B0
		private void InitAux()
		{
			if (MobileParty.MainParty.MapEvent != null)
			{
				this._mapEvent = MobileParty.MainParty.MapEvent;
				this.SetupFields(this._mapEvent.AttackerSide.LeaderParty, this._mapEvent.DefenderSide.LeaderParty);
				this.CheckNearbyPartiesToJoinPlayerMapEvent();
			}
		}

		// Token: 0x06002412 RID: 9234 RVA: 0x00097708 File Offset: 0x00095908
		public void SetupFields(PartyBase attackerParty, PartyBase defenderParty)
		{
			this._attackerParty = attackerParty;
			this._defenderParty = defenderParty;
			MobileParty mobileParty = (defenderParty.IsMobile && defenderParty != PartyBase.MainParty && defenderParty.MobileParty != MobileParty.MainParty.AttachedTo) ? defenderParty.MobileParty : ((attackerParty.IsMobile && attackerParty != PartyBase.MainParty && attackerParty.MobileParty != MobileParty.MainParty.AttachedTo) ? attackerParty.MobileParty : null);
			if (this._defenderParty.IsSettlement)
			{
				this.EncounterSettlementAux = defenderParty.Settlement;
			}
			else if (this._attackerParty.IsSettlement)
			{
				this.EncounterSettlementAux = this._attackerParty.Settlement;
			}
			else if (mobileParty.BesiegerCamp != null)
			{
				this.EncounterSettlementAux = mobileParty.BesiegerCamp.SiegeEvent.BesiegedSettlement;
			}
			PartyBase encounteredParty;
			if (mobileParty == null)
			{
				Settlement encounterSettlementAux = this.EncounterSettlementAux;
				encounteredParty = ((encounterSettlementAux != null) ? encounterSettlementAux.Party : null);
			}
			else
			{
				encounteredParty = mobileParty.Party;
			}
			this._encounteredParty = encounteredParty;
			if (MapEvent.PlayerMapEvent != null)
			{
				this.PlayerSide = MapEvent.PlayerMapEvent.PlayerSide;
			}
			else if (defenderParty == PartyBase.MainParty || (defenderParty.MobileParty != null && defenderParty.MobileParty == MobileParty.MainParty.AttachedTo) || (defenderParty.IsSettlement && (defenderParty.Settlement.MapFaction == MobileParty.MainParty.MapFaction || MobileParty.MainParty.CurrentSettlement == defenderParty.Settlement)))
			{
				this.PlayerSide = BattleSideEnum.Defender;
			}
			else
			{
				this.PlayerSide = BattleSideEnum.Attacker;
			}
			this.OpponentSide = this.PlayerSide.GetOppositeSide();
			if (!this._encounteredParty.IsSettlement)
			{
				MobileParty.MainParty.Ai.SetMoveModeHold();
			}
		}

		// Token: 0x06002413 RID: 9235 RVA: 0x000978A0 File Offset: 0x00095AA0
		internal void OnPartyJoinEncounter(MobileParty newParty)
		{
			if (PlayerEncounter.Battle != null)
			{
				if (PlayerEncounter.Battle.CanPartyJoinBattle(PartyBase.MainParty, PartyBase.MainParty.Side))
				{
					newParty.Party.MapEventSide = PartyBase.MainParty.MapEventSide;
					return;
				}
				if (newParty == MobileParty.MainParty && PlayerEncounter.Battle.IsRaid && PlayerEncounter.Battle.AttackerSide.LeaderParty != MobileParty.MainParty.Party && PlayerEncounter.Battle.DefenderSide.TroopCount == 0)
				{
					return;
				}
				MobileParty.MainParty.Ai.SetMoveModeHold();
				string newPartyJoinMenu = Campaign.Current.Models.EncounterGameMenuModel.GetNewPartyJoinMenu(newParty);
				if (PlayerEncounter.Battle.CanPartyJoinBattle(PartyBase.MainParty, PartyBase.MainParty.OpponentSide))
				{
					newParty.Party.MapEventSide = PartyBase.MainParty.MapEventSide.OtherSide;
				}
				if (!string.IsNullOrEmpty(newPartyJoinMenu))
				{
					GameMenu.SwitchToMenu(newPartyJoinMenu);
				}
			}
		}

		// Token: 0x06002414 RID: 9236 RVA: 0x00097994 File Offset: 0x00095B94
		private void CheckNearbyPartiesToJoinPlayerMapEvent()
		{
			if (this._mapEvent == null || this._mapEvent.IsRaid || this._mapEvent.IsSiegeAssault || this._mapEvent.IsForcingSupplies || this._mapEvent.IsForcingVolunteers)
			{
				return;
			}
			if (this._mapEvent.MapEventSettlement != null && this._mapEvent.MapEventSettlement.IsHideout)
			{
				return;
			}
			List<MobileParty> list = new List<MobileParty>();
			List<MobileParty> list2 = new List<MobileParty>();
			foreach (MapEventParty mapEventParty in this._mapEvent.PartiesOnSide(this.PlayerSide))
			{
				if (mapEventParty.Party.IsMobile)
				{
					list.Add(mapEventParty.Party.MobileParty);
				}
			}
			foreach (MapEventParty mapEventParty2 in this._mapEvent.PartiesOnSide(this.PlayerSide.GetOppositeSide()))
			{
				if (mapEventParty2.Party.IsMobile)
				{
					list2.Add(mapEventParty2.Party.MobileParty);
				}
			}
			PlayerEncounter.Current.FindNonAttachedNpcPartiesWhoWillJoinEvent(ref list, ref list2);
			foreach (MobileParty party in list)
			{
				this._mapEvent.GetMapEventSide(this.PlayerSide).AddNearbyPartyToPlayerMapEvent(party);
			}
			foreach (MobileParty party2 in list2)
			{
				this._mapEvent.GetMapEventSide(this.PlayerSide.GetOppositeSide()).AddNearbyPartyToPlayerMapEvent(party2);
			}
		}

		// Token: 0x06002415 RID: 9237 RVA: 0x00097B94 File Offset: 0x00095D94
		private static TerrainType GetTerrainByCount(List<TerrainType> terrainTypeSamples, TerrainType currentPositionTerrainType)
		{
			for (int i = 0; i < terrainTypeSamples.Count; i++)
			{
				if (terrainTypeSamples[i] == TerrainType.Snow)
				{
					terrainTypeSamples[i] = TerrainType.Plain;
				}
			}
			if (currentPositionTerrainType == TerrainType.Plain || currentPositionTerrainType == TerrainType.Desert || currentPositionTerrainType == TerrainType.Swamp || currentPositionTerrainType == TerrainType.Steppe)
			{
				int num = (int)((float)terrainTypeSamples.Count * 0.33f);
				for (int j = 0; j < num; j++)
				{
					terrainTypeSamples.Add(currentPositionTerrainType);
				}
			}
			Dictionary<TerrainType, int> dictionary = new Dictionary<TerrainType, int>();
			foreach (TerrainType terrainType in terrainTypeSamples)
			{
				if (!dictionary.ContainsKey(terrainType))
				{
					dictionary.Add(terrainType, 1);
				}
				else
				{
					Dictionary<TerrainType, int> dictionary2 = dictionary;
					TerrainType key = terrainType;
					int num2 = dictionary2[key];
					dictionary2[key] = num2 + 1;
				}
			}
			KeyValuePair<TerrainType, int> keyValuePair = new KeyValuePair<TerrainType, int>(TerrainType.Plain, 0);
			foreach (KeyValuePair<TerrainType, int> keyValuePair2 in dictionary)
			{
				if ((keyValuePair2.Key == TerrainType.Plain || keyValuePair2.Key == TerrainType.Desert || keyValuePair2.Key == TerrainType.Swamp || keyValuePair2.Key == TerrainType.Steppe) && keyValuePair2.Value > keyValuePair.Value)
				{
					keyValuePair = keyValuePair2;
				}
			}
			return keyValuePair.Key;
		}

		// Token: 0x06002416 RID: 9238 RVA: 0x00097CF0 File Offset: 0x00095EF0
		private static List<TerrainType> GetSceneProperties(List<TerrainType> terrainTypeSamples, int forestCount, out ForestDensity forestDensity)
		{
			forestDensity = ForestDensity.None;
			float num = (float)forestCount / (float)terrainTypeSamples.Count;
			if (num > 0.1f && num < 0.5f)
			{
				forestDensity = ForestDensity.Low;
			}
			else if (num >= 0.5f)
			{
				forestDensity = ForestDensity.High;
			}
			List<TerrainType> list = new List<TerrainType>();
			foreach (TerrainType item in terrainTypeSamples)
			{
				if (!list.Contains(item))
				{
					list.Add(item);
				}
			}
			return list;
		}

		// Token: 0x06002417 RID: 9239 RVA: 0x00097D7C File Offset: 0x00095F7C
		public static string GetBattleSceneForMapPatch(MapPatchData mapPatch)
		{
			MBList<SingleplayerBattleSceneData> mblist = (from scene in GameSceneDataManager.Instance.SingleplayerBattleScenes
			where scene.MapIndices.Contains(mapPatch.sceneIndex)
			select scene).ToMBList<SingleplayerBattleSceneData>();
			string sceneID;
			if (mblist.IsEmpty<SingleplayerBattleSceneData>())
			{
				Debug.FailedAssert("Battle scene for map patch with scene index " + mapPatch.sceneIndex + " does not exist. Picking a random scene", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\Encounters\\PlayerEncounter.cs", "GetBattleSceneForMapPatch", 735);
				sceneID = GameSceneDataManager.Instance.SingleplayerBattleScenes.GetRandomElement<SingleplayerBattleSceneData>().SceneID;
			}
			else if (mblist.Count > 1)
			{
				Debug.FailedAssert("Multiple battle scenes for map patch with scene index " + mapPatch.sceneIndex + " are defined. Picking a matching scene randomly", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\Encounters\\PlayerEncounter.cs", "GetBattleSceneForMapPatch", 740);
				sceneID = mblist.GetRandomElement<SingleplayerBattleSceneData>().SceneID;
			}
			else
			{
				sceneID = mblist[0].SceneID;
			}
			return sceneID;
		}

		// Token: 0x06002418 RID: 9240 RVA: 0x00097E70 File Offset: 0x00096070
		public static string GetConversationSceneForMapPosition(Vec2 position2D)
		{
			TerrainType currentPositionTerrainType;
			List<TerrainType> environmentTerrainTypesCount = Campaign.Current.MapSceneWrapper.GetEnvironmentTerrainTypesCount(position2D, out currentPositionTerrainType);
			int num = 0;
			foreach (TerrainType terrainType in environmentTerrainTypesCount)
			{
				num += ((terrainType == TerrainType.Forest) ? 1 : 0);
			}
			TerrainType terrainByCount = PlayerEncounter.GetTerrainByCount(environmentTerrainTypesCount, currentPositionTerrainType);
			ForestDensity forestDensity;
			List<TerrainType> sceneProperties = PlayerEncounter.GetSceneProperties(environmentTerrainTypesCount, num, out forestDensity);
			int num2 = 0;
			Dictionary<ConversationSceneData, int> dictionary = new Dictionary<ConversationSceneData, int>();
			foreach (ConversationSceneData key in GameSceneDataManager.Instance.ConversationScenes)
			{
				if (key.Terrain == terrainByCount)
				{
					int num3 = 0;
					if ((forestDensity == ForestDensity.None && key.ForestDensity == ForestDensity.None) || (forestDensity != ForestDensity.None && key.ForestDensity > ForestDensity.None))
					{
						num3++;
					}
					int num4 = 2 - MathF.Abs(forestDensity - key.ForestDensity);
					num3 += num4;
					foreach (TerrainType item in sceneProperties)
					{
						if (key.TerrainTypes.Contains(item))
						{
							num3 += 3;
						}
					}
					dictionary.Add(key, num3);
					if (num3 > num2)
					{
						num2 = num3;
					}
				}
			}
			MBList<ConversationSceneData> mblist = new MBList<ConversationSceneData>();
			foreach (KeyValuePair<ConversationSceneData, int> keyValuePair in dictionary)
			{
				if (keyValuePair.Value == num2)
				{
					mblist.Add(keyValuePair.Key);
				}
			}
			return ((mblist.Count > 0) ? mblist.GetRandomElement<ConversationSceneData>() : GameSceneDataManager.Instance.ConversationScenes.GetRandomElement<ConversationSceneData>()).SceneID;
		}

		// Token: 0x06002419 RID: 9241 RVA: 0x0009807C File Offset: 0x0009627C
		private MapEvent StartBattleInternal()
		{
			if (this._mapEvent == null)
			{
				if (this.ForceRaid)
				{
					this._mapEvent = RaidEventComponent.CreateRaidEvent(this._attackerParty, this._defenderParty).MapEvent;
				}
				else if (this.ForceSallyOut)
				{
					this._mapEvent = Campaign.Current.MapEventManager.StartSallyOutMapEvent(this._attackerParty, this._defenderParty);
				}
				else if (this.ForceVolunteers)
				{
					this._mapEvent = ForceVolunteersEventComponent.CreateForceSuppliesEvent(this._attackerParty, this._defenderParty).MapEvent;
				}
				else if (this.ForceSupplies)
				{
					this._mapEvent = ForceSuppliesEventComponent.CreateForceSuppliesEvent(this._attackerParty, this._defenderParty).MapEvent;
				}
				else if (this._defenderParty.IsSettlement)
				{
					if (this._defenderParty.Settlement.IsFortification)
					{
						this._mapEvent = Campaign.Current.MapEventManager.StartSiegeMapEvent(this._attackerParty, this._defenderParty);
					}
					else if (this._defenderParty.Settlement.IsVillage)
					{
						this._mapEvent = RaidEventComponent.CreateRaidEvent(this._attackerParty, this._defenderParty).MapEvent;
					}
					else if (this._defenderParty.Settlement.IsHideout)
					{
						this._mapEvent = HideoutEventComponent.CreateHideoutEvent(this._attackerParty, this._defenderParty).MapEvent;
					}
					else
					{
						Debug.FailedAssert("Proper mapEvent type could not be set for the battle.", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\Encounters\\PlayerEncounter.cs", "StartBattleInternal", 860);
					}
				}
				else if (this._isSallyOutAmbush)
				{
					this._mapEvent = SiegeAmbushEventComponent.CreateSiegeAmbushEvent(this._attackerParty, this._defenderParty).MapEvent;
				}
				else if (this._attackerParty.IsMobile && this._attackerParty.MobileParty.CurrentSettlement != null && this._attackerParty.MobileParty.CurrentSettlement.SiegeEvent != null)
				{
					this._mapEvent = Campaign.Current.MapEventManager.StartSallyOutMapEvent(this._attackerParty, this._defenderParty);
				}
				else if (this._defenderParty.IsMobile && this._defenderParty.MobileParty.BesiegedSettlement != null)
				{
					this._mapEvent = Campaign.Current.MapEventManager.StartSiegeOutsideMapEvent(this._attackerParty, this._defenderParty);
				}
				else
				{
					this._mapEvent = FieldBattleEventComponent.CreateFieldBattleEvent(this._attackerParty, this._defenderParty).MapEvent;
				}
			}
			this.CheckNearbyPartiesToJoinPlayerMapEvent();
			return this._mapEvent;
		}

		// Token: 0x0600241A RID: 9242 RVA: 0x000982F5 File Offset: 0x000964F5
		public static MapEvent StartBattle()
		{
			return PlayerEncounter.Current.StartBattleInternal();
		}

		// Token: 0x0600241B RID: 9243 RVA: 0x00098304 File Offset: 0x00096504
		private void JoinBattleInternal(BattleSideEnum side)
		{
			this.PlayerSide = side;
			if (side == BattleSideEnum.Defender)
			{
				this.OpponentSide = BattleSideEnum.Attacker;
			}
			else if (side == BattleSideEnum.Attacker)
			{
				this.OpponentSide = BattleSideEnum.Defender;
			}
			if (PlayerEncounter.EncounteredBattle != null)
			{
				this._mapEvent = PlayerEncounter.EncounteredBattle;
				this._encounteredParty = ((this.PlayerSide == BattleSideEnum.Attacker) ? PlayerEncounter.EncounteredBattle.DefenderSide.LeaderParty : PlayerEncounter.EncounteredBattle.AttackerSide.LeaderParty);
				this.PartiesStrengthRatioBeforePlayerJoin = this.CalculateStrengthOfParties();
				PartyBase.MainParty.MapEventSide = PlayerEncounter.EncounteredBattle.GetMapEventSide(side);
				this.EncounterSettlementAux = this._mapEvent.MapEventSettlement;
				if (PlayerEncounter.EncounteredBattle.IsSiegeAssault && this.PlayerSide == BattleSideEnum.Attacker)
				{
					MobileParty.MainParty.BesiegerCamp = this._encounteredParty.SiegeEvent.BesiegerCamp;
				}
				this.IsJoinedBattle = true;
				this.CheckNearbyPartiesToJoinPlayerMapEvent();
				return;
			}
			PlayerEncounter.Finish(PlayerEncounter.InsideSettlement);
		}

		// Token: 0x0600241C RID: 9244 RVA: 0x000983EC File Offset: 0x000965EC
		private float CalculateStrengthOfParties()
		{
			float num = 0f;
			float num2 = 0f;
			foreach (MapEventParty mapEventParty in this._mapEvent.DefenderSide.Parties)
			{
				num += mapEventParty.Party.TotalStrength;
			}
			foreach (MapEventParty mapEventParty2 in this._mapEvent.AttackerSide.Parties)
			{
				num2 += mapEventParty2.Party.TotalStrength;
			}
			return num / num2;
		}

		// Token: 0x0600241D RID: 9245 RVA: 0x000984B4 File Offset: 0x000966B4
		public static void JoinBattle(BattleSideEnum side)
		{
			PlayerEncounter.Current.JoinBattleInternal(side);
		}

		// Token: 0x0600241E RID: 9246 RVA: 0x000984C1 File Offset: 0x000966C1
		private void PlayerSurrenderInternal()
		{
			this._playerSurrender = true;
			if (PlayerEncounter.Battle == null)
			{
				PlayerEncounter.StartBattle();
			}
			this._mapEvent.DoSurrender(PartyBase.MainParty.Side);
			MobileParty.MainParty.BesiegerCamp = null;
		}

		// Token: 0x0600241F RID: 9247 RVA: 0x000984F7 File Offset: 0x000966F7
		private void EnemySurrenderInternal()
		{
			this._enemySurrender = true;
			this._mapEvent.DoSurrender(PartyBase.MainParty.OpponentSide);
		}

		// Token: 0x06002420 RID: 9248 RVA: 0x00098515 File Offset: 0x00096715
		public static void Start()
		{
			Campaign.Current.PlayerEncounter = new PlayerEncounter();
		}

		// Token: 0x06002421 RID: 9249 RVA: 0x00098526 File Offset: 0x00096726
		public static void ProtectPlayerSide(float hoursToProtect = 1f)
		{
			MobileParty.MainParty.TeleportPartyToSafePosition(3.3f, 3f);
			MobileParty.MainParty.IgnoreForHours(hoursToProtect);
		}

		// Token: 0x06002422 RID: 9250 RVA: 0x00098548 File Offset: 0x00096748
		public static void Finish(bool forcePlayerOutFromSettlement = true)
		{
			if (MobileParty.MainParty.Army == null || MobileParty.MainParty.Army.LeaderParty == PlayerEncounter.EncounteredMobileParty)
			{
				Campaign.Current.TimeControlMode = CampaignTimeControlMode.Stop;
			}
			if (Campaign.Current.CurrentMenuContext != null)
			{
				GameMenu.ExitToLast();
			}
			if (PlayerEncounter.Current != null)
			{
				bool flag = PlayerSiege.PlayerSiegeEvent != null && PlayerSiege.PlayerSide == BattleSideEnum.Attacker && MobileParty.MainParty.MapEvent != null && !MobileParty.MainParty.MapEvent.IsSiegeAssault && MobileParty.MainParty.MapEvent.HasWinner && MobileParty.MainParty.MapEvent.PlayerSide == BattleSideEnum.Defender && MobileParty.MainParty.BesiegedSettlement != null;
				if ((flag || PlayerEncounter.Current._isSiegeInterruptedByEnemyDefection) && Hero.MainHero.PartyBelongedToAsPrisoner == null && !PlayerEncounter.Current._leaveEncounter && PlayerEncounter.Current._encounteredParty.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					GameMenu.ActivateGameMenu("continue_siege_after_attack");
					if (PlayerEncounter.Current._isSiegeInterruptedByEnemyDefection)
					{
						PlayerEncounter.Current._isSiegeInterruptedByEnemyDefection = false;
					}
				}
				if ((flag || PlayerEncounter.Current._isSiegeInterruptedByEnemyDefection) && Hero.MainHero.PartyBelongedToAsPrisoner != null && PlayerEncounter.Current._leaveEncounter)
				{
					MobileParty.MainParty.BesiegerCamp = null;
				}
				PlayerEncounter.Current.FirstInit = true;
				Settlement encounterSettlement = PlayerEncounter.EncounterSettlement;
				if (encounterSettlement != null)
				{
					encounterSettlement.OnPlayerEncounterFinish();
				}
				PlayerEncounter.Current.FinalizeBattle();
				PlayerEncounter.Current.FinishEncounterInternal();
				if (PlayerEncounter.CurrentBattleSimulation != null)
				{
					MapState mapState = Game.Current.GameStateManager.LastOrDefault<MapState>();
					if (mapState != null && mapState.IsSimulationActive)
					{
						mapState.EndBattleSimulation();
					}
					PlayerEncounter.Current.BattleSimulation = null;
				}
				if (PlayerEncounter.InsideSettlement && MobileParty.MainParty.AttachedTo == null && forcePlayerOutFromSettlement)
				{
					PlayerEncounter.LeaveSettlement();
				}
			}
			Campaign.Current.PlayerEncounter = null;
			Campaign.Current.LocationEncounter = null;
			MobileParty.MainParty.Ai.SetMoveModeHold();
		}

		// Token: 0x06002423 RID: 9251 RVA: 0x0009873C File Offset: 0x0009693C
		private void FinishEncounterInternal()
		{
			if (this._encounteredParty != null && this._encounteredParty.IsMobile && MobileParty.MainParty.AttachedTo == null && FactionManager.IsAtWarAgainstFaction(this._encounteredParty.MapFaction, PartyBase.MainParty.MapFaction) && this._encounteredParty.MobileParty.IsActive)
			{
				MobileParty.MainParty.TeleportPartyToSafePosition(0.3f, 0.1f);
				this._encounteredParty.MobileParty.Ai.SetDoNotAttackMainParty(2);
			}
		}

		// Token: 0x06002424 RID: 9252 RVA: 0x000987C4 File Offset: 0x000969C4
		private void UpdateInternal()
		{
			this._mapEvent = MapEvent.PlayerMapEvent;
			if (PlayerEncounter.EncounteredPartySurrendered && this.EncounterState == PlayerEncounterState.Begin)
			{
				this.EncounterState = PlayerEncounterState.Wait;
			}
			this._stateHandled = false;
			while (!this._stateHandled)
			{
				if (PlayerEncounter.Current._leaveEncounter)
				{
					PlayerEncounter.Finish(true);
					this._stateHandled = true;
				}
				if (!this._stateHandled)
				{
					switch (this.EncounterState)
					{
					case PlayerEncounterState.Begin:
						this.DoBegin();
						break;
					case PlayerEncounterState.Wait:
						this.DoWait();
						break;
					case PlayerEncounterState.PrepareResults:
						this.DoPrepareResults();
						break;
					case PlayerEncounterState.ApplyResults:
						this.DoApplyResults();
						break;
					case PlayerEncounterState.PlayerVictory:
						this.DoPlayerVictory();
						break;
					case PlayerEncounterState.PlayerTotalDefeat:
						this.DoPlayerDefeat();
						break;
					case PlayerEncounterState.CaptureHeroes:
						this.DoCaptureHeroes();
						break;
					case PlayerEncounterState.FreeHeroes:
						this.DoFreeHeroes();
						break;
					case PlayerEncounterState.LootParty:
						this.DoLootParty();
						break;
					case PlayerEncounterState.LootInventory:
						this.DoLootInventory();
						break;
					case PlayerEncounterState.End:
						this.DoEnd();
						break;
					default:
						Debug.FailedAssert("[DEBUG]Invalid map event state: " + this._mapEventState, "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\Encounters\\PlayerEncounter.cs", "UpdateInternal", 1132);
						break;
					}
				}
			}
		}

		// Token: 0x06002425 RID: 9253 RVA: 0x000988EC File Offset: 0x00096AEC
		private void EndBattleByCheatInternal(bool playerWon)
		{
			if (playerWon)
			{
				foreach (MapEventParty mapEventParty in this._mapEvent.PartiesOnSide(this.OpponentSide))
				{
					for (int i = 0; i < mapEventParty.Party.MemberRoster.Count; i++)
					{
						int elementNumber = mapEventParty.Party.MemberRoster.GetElementNumber(i);
						int elementWoundedNumber = mapEventParty.Party.MemberRoster.GetElementWoundedNumber(i);
						int maxValue = elementNumber - elementWoundedNumber;
						int num = elementWoundedNumber + MBRandom.RandomInt(maxValue);
						num = ((num <= 0 && elementNumber >= 0) ? 1 : num);
						mapEventParty.Party.MemberRoster.SetElementNumber(i, num);
						mapEventParty.Party.MemberRoster.SetElementWoundedNumber(i, num);
					}
				}
			}
		}

		// Token: 0x06002426 RID: 9254 RVA: 0x000989DC File Offset: 0x00096BDC
		public static void EndBattleByCheat(bool playerWon)
		{
			PlayerEncounter.Current.EndBattleByCheatInternal(playerWon);
		}

		// Token: 0x06002427 RID: 9255 RVA: 0x000989E9 File Offset: 0x00096BE9
		public static void Update()
		{
			PlayerEncounter.Current.UpdateInternal();
		}

		// Token: 0x06002428 RID: 9256 RVA: 0x000989F5 File Offset: 0x00096BF5
		private void DoBegin()
		{
			this.EncounterState = PlayerEncounterState.Wait;
			this._stateHandled = true;
		}

		// Token: 0x06002429 RID: 9257 RVA: 0x00098A05 File Offset: 0x00096C05
		public static void DoMeeting()
		{
			PlayerEncounter.Current.DoMeetingInternal();
		}

		// Token: 0x0600242A RID: 9258 RVA: 0x00098A11 File Offset: 0x00096C11
		public static void SetMeetingDone()
		{
			PlayerEncounter.Current._meetingDone = true;
		}

		// Token: 0x0600242B RID: 9259 RVA: 0x00098A20 File Offset: 0x00096C20
		private void DoMeetingInternal()
		{
			PartyBase partyBase = this._encounteredParty;
			if (partyBase.IsSettlement)
			{
				foreach (MapEventParty mapEventParty in MobileParty.MainParty.MapEvent.DefenderSide.Parties)
				{
					if (!mapEventParty.Party.IsSettlement)
					{
						partyBase = mapEventParty.Party;
						break;
					}
				}
			}
			this.EncounterState = PlayerEncounterState.Begin;
			this._stateHandled = true;
			if (PlayerEncounter.PlayerIsAttacker && this._defenderParty.IsMobile && this._defenderParty.MobileParty.Army != null && this._defenderParty.MobileParty.Army.LeaderParty == this._defenderParty.MobileParty && (this._defenderParty.SiegeEvent != null || (!this._defenderParty.MobileParty.MapFaction.IsAtWarWith(MobileParty.MainParty.MapFaction) && !this._defenderParty.MobileParty.Army.LeaderParty.AttachedParties.Contains(MobileParty.MainParty))))
			{
				GameMenu.SwitchToMenu("army_encounter");
				return;
			}
			Campaign.Current.CurrentConversationContext = ConversationContext.PartyEncounter;
			this._meetingDone = true;
			CharacterObject conversationCharacterPartyLeader = ConversationHelper.GetConversationCharacterPartyLeader(partyBase);
			ConversationCharacterData playerCharacterData = new ConversationCharacterData(CharacterObject.PlayerCharacter, PartyBase.MainParty, true, false, false, false, false, false);
			ConversationCharacterData conversationPartnerData = new ConversationCharacterData(conversationCharacterPartyLeader, partyBase, true, false, false, false, false, false);
			CampaignMapConversation.OpenConversation(playerCharacterData, conversationPartnerData);
		}

		// Token: 0x0600242C RID: 9260 RVA: 0x00098BAC File Offset: 0x00096DAC
		private void ContinueBattle()
		{
			Debug.Print("[PlayerEncounter.ContinueBattle Start]", 0, Debug.DebugColor.White, 17592186044416UL);
			MapEventSide mapEventSide = this._mapEvent.GetMapEventSide(this._mapEvent.PlayerSide);
			MapEventSide otherSide = mapEventSide.OtherSide;
			this._mapEvent.RecalculateStrengthOfSides();
			float num = this._mapEvent.StrengthOfSide[(int)mapEventSide.MissionSide];
			float num2 = this._mapEvent.StrengthOfSide[(int)otherSide.MissionSide];
			float num3 = num / (num + num2);
			Debug.Print("playerSideStrength: " + num, 0, Debug.DebugColor.White, 17592186044416UL);
			Debug.Print("otherSideStrength: " + num2, 0, Debug.DebugColor.White, 17592186044416UL);
			Debug.Print("playerSideStrengthRatio: " + num3, 0, Debug.DebugColor.White, 17592186044416UL);
			if (num3 >= 0.95f && otherSide.GetTotalHealthyHeroCountOfSide() <= 0)
			{
				Debug.Print("Player side wins according to the strength ratio.", 0, Debug.DebugColor.White, 17592186044416UL);
				MapEvent mapEvent = this._mapEvent;
				if (mapEvent != null)
				{
					mapEvent.SetOverrideWinner(this._mapEvent.PlayerSide);
				}
				PlayerEncounter.EnemySurrender = true;
				this.EncounterState = PlayerEncounterState.PrepareResults;
			}
			else if (num3 < 0.05f && mapEventSide.GetTotalHealthyHeroCountOfSide() <= 0)
			{
				Debug.Print("Other side wins according to the strength ratio.", 0, Debug.DebugColor.White, 17592186044416UL);
				MapEvent mapEvent2 = this._mapEvent;
				if (mapEvent2 != null)
				{
					mapEvent2.SetOverrideWinner(otherSide.MissionSide);
				}
				this.EncounterState = PlayerEncounterState.PrepareResults;
			}
			else
			{
				Debug.Print("Battle continues.", 0, Debug.DebugColor.White, 17592186044416UL);
				Debug.Print("Other side strength by party:", 0, Debug.DebugColor.White, 17592186044416UL);
				foreach (MapEventParty mapEventParty in otherSide.Parties)
				{
					Debug.Print(string.Concat(new object[]
					{
						"party: ",
						mapEventParty.Party.Id,
						": ",
						mapEventParty.Party.Name,
						", strength: ",
						mapEventParty.Party.TotalStrength,
						", healthy count: ",
						mapEventParty.Party.MemberRoster.TotalHealthyCount,
						", wounded count: ",
						mapEventParty.Party.MemberRoster.TotalWounded
					}), 0, Debug.DebugColor.White, 17592186044416UL);
				}
				this._mapEvent.AttackerSide.CommitXpGains();
				this._mapEvent.DefenderSide.CommitXpGains();
				this._mapEvent.ApplyRenownAndInfluenceChanges();
				this._mapEvent.SetOverrideWinner(BattleSideEnum.None);
				if (this._mapEvent.IsSiegeAssault && otherSide == this._mapEvent.AttackerSide)
				{
					CampaignBattleResult campaignBattleResult = this._campaignBattleResult;
					if (campaignBattleResult != null && campaignBattleResult.EnemyRetreated)
					{
						List<MapEventParty> list = this._mapEvent.AttackerSide.Parties.ToList<MapEventParty>();
						this._mapEvent.FinishBattleAndKeepSiegeEvent();
						this._mapEvent = null;
						foreach (MapEventParty mapEventParty2 in list)
						{
							mapEventParty2.Party.SetVisualAsDirty();
							if (mapEventParty2.Party.IsMobile)
							{
								mapEventParty2.Party.MobileParty.Ai.SetMoveBesiegeSettlement(Settlement.CurrentSettlement);
								mapEventParty2.Party.MobileParty.Ai.RecalculateShortTermAi();
							}
						}
						GameMenu.ActivateGameMenu("menu_siege_strategies");
					}
				}
				this._campaignBattleResult = null;
				this._stateHandled = true;
			}
			Debug.Print("[PlayerEncounter.ContinueBattle End]", 0, Debug.DebugColor.White, 17592186044416UL);
		}

		// Token: 0x0600242D RID: 9261 RVA: 0x00098F90 File Offset: 0x00097190
		private void DoWait()
		{
			MBTextManager.SetTextVariable("PARTY", MapEvent.PlayerMapEvent.GetLeaderParty(PartyBase.MainParty.OpponentSide).Name, false);
			if (!PlayerEncounter.EncounteredPartySurrendered)
			{
				MBTextManager.SetTextVariable("ENCOUNTER_TEXT", GameTexts.FindText("str_you_have_encountered_PARTY", null), true);
			}
			else
			{
				MBTextManager.SetTextVariable("ENCOUNTER_TEXT", GameTexts.FindText("str_you_have_encountered_PARTY_they_surrendered", null), true);
			}
			if (this.CheckIfBattleShouldContinueAfterBattleMission())
			{
				this.ContinueBattle();
				return;
			}
			if (this._mapEvent != null && this._mapEvent.IsSiegeAssault)
			{
				this._mapEvent.CheckIfOneSideHasLost();
				this._campaignBattleResult = CampaignBattleResult.GetResult(this._mapEvent.BattleState, false);
			}
			if (this._campaignBattleResult != null && this._campaignBattleResult.BattleResolved)
			{
				if (this._campaignBattleResult.PlayerVictory)
				{
					MapEvent mapEvent = this._mapEvent;
					if (mapEvent != null)
					{
						mapEvent.SetOverrideWinner(PartyBase.MainParty.Side);
					}
				}
				else
				{
					bool flag = true;
					if (this._mapEvent != null && this._mapEvent.IsHideoutBattle)
					{
						this._mapEvent.MapEventSettlement.Hideout.UpdateNextPossibleAttackTime();
						if (this._mapEvent.GetMapEventSide(this.PlayerSide).RecalculateMemberCountOfSide() > 0)
						{
							flag = false;
						}
					}
					if (flag)
					{
						MapEvent mapEvent2 = this._mapEvent;
						if (mapEvent2 != null)
						{
							mapEvent2.SetOverrideWinner(PartyBase.MainParty.OpponentSide);
						}
					}
				}
				this.EncounterState = PlayerEncounterState.PrepareResults;
				return;
			}
			if (this.BattleSimulation != null && (PlayerEncounter.BattleState == BattleState.AttackerVictory || PlayerEncounter.BattleState == BattleState.DefenderVictory))
			{
				if (this._mapEvent.WinningSide == this.PlayerSide)
				{
					PlayerEncounter.EnemySurrender = true;
				}
				else
				{
					bool totalManCount = MobileParty.MainParty.MemberRoster.TotalManCount != 0;
					int totalWounded = MobileParty.MainParty.MemberRoster.TotalWounded;
					if ((totalManCount ? 1 : 0) - totalWounded == 0)
					{
						PlayerEncounter.PlayerSurrender = true;
					}
				}
				this.EncounterState = PlayerEncounterState.PrepareResults;
				return;
			}
			if (this.BattleSimulation != null && this.BattleSimulation.IsSimulationFinished)
			{
				MapEvent mapEvent3 = this._mapEvent;
				if (((mapEvent3 != null) ? mapEvent3.MapEventSettlement : null) != null && PlayerEncounter.BattleState == BattleState.None && this._mapEvent.IsSiegeAssault && PlayerSiege.PlayerSiegeEvent != null)
				{
					this._stateHandled = true;
					PlayerSiege.PlayerSiegeEvent.BreakSiegeEngine(PlayerSiege.PlayerSiegeEvent.GetSiegeEventSide(this._mapEvent.PlayerSide), DefaultSiegeEngineTypes.Preparations);
					return;
				}
			}
			if (this._mapEvent != null && (!this._mapEvent.IsRaid || PlayerEncounter.PlayerSurrender) && this._mapEvent.HasWinner)
			{
				this.EncounterState = PlayerEncounterState.PrepareResults;
				return;
			}
			this._stateHandled = true;
			if (this.IsJoinedBattle && Campaign.Current.CurrentMenuContext != null && Campaign.Current.CurrentMenuContext.GameMenu.StringId == "join_encounter")
			{
				PlayerEncounter.LeaveBattle();
			}
			if (this._mapEvent != null && this._mapEvent.IsHideoutBattle)
			{
				this._mapEvent.MapEventSettlement.Hideout.UpdateNextPossibleAttackTime();
			}
		}

		// Token: 0x0600242E RID: 9262 RVA: 0x00099260 File Offset: 0x00097460
		public static bool CheckIfLeadingAvaliable()
		{
			bool flag = Hero.MainHero.PartyBelongedTo != null && !Hero.MainHero.IsWounded;
			bool flag2 = Hero.MainHero.PartyBelongedTo != null && Hero.MainHero.PartyBelongedTo.Army != null && Hero.MainHero.PartyBelongedTo.Army.ArmyOwner != Hero.MainHero;
			bool flag3 = false;
			foreach (MapEventParty mapEventParty in MobileParty.MainParty.MapEvent.PartiesOnSide(MobileParty.MainParty.MapEvent.PlayerSide))
			{
				if (mapEventParty.Party != MobileParty.MainParty.Party && mapEventParty.Party.LeaderHero != null && mapEventParty.Party.LeaderHero.Clan.Renown > Clan.PlayerClan.Renown)
				{
					flag3 = true;
					break;
				}
			}
			return flag && (flag2 || flag3);
		}

		// Token: 0x0600242F RID: 9263 RVA: 0x00099378 File Offset: 0x00097578
		public static Hero GetLeadingHero()
		{
			if (Hero.MainHero.PartyBelongedTo != null && Hero.MainHero.PartyBelongedTo.Army != null)
			{
				return MobileParty.MainParty.Army.ArmyOwner;
			}
			foreach (MapEventParty mapEventParty in MobileParty.MainParty.MapEvent.PartiesOnSide(MobileParty.MainParty.MapEvent.PlayerSide))
			{
				if (mapEventParty.Party != MobileParty.MainParty.Party && mapEventParty.Party.LeaderHero != null && mapEventParty.Party.LeaderHero.Clan.Renown > Clan.PlayerClan.Renown)
				{
					return mapEventParty.Party.LeaderHero;
				}
			}
			return Hero.MainHero;
		}

		// Token: 0x06002430 RID: 9264 RVA: 0x00099464 File Offset: 0x00097664
		private void DoPrepareResults()
		{
			this._mapEvent.CalculateBattleResults(false);
			this.EncounterState = PlayerEncounterState.ApplyResults;
		}

		// Token: 0x06002431 RID: 9265 RVA: 0x00099479 File Offset: 0x00097679
		public static void SetPlayerVictorious()
		{
			PlayerEncounter.Current.SetPlayerVictoriousInternal();
		}

		// Token: 0x06002432 RID: 9266 RVA: 0x00099485 File Offset: 0x00097685
		public void SetIsSallyOutAmbush(bool value)
		{
			if (PlayerEncounter.Current._isSallyOutAmbush && !value)
			{
				this._campaignBattleResult = null;
			}
			PlayerEncounter.Current._isSallyOutAmbush = value;
		}

		// Token: 0x06002433 RID: 9267 RVA: 0x000994A8 File Offset: 0x000976A8
		public void SetPlayerSiegeInterruptedByEnemyDefection()
		{
			PlayerEncounter.Current._isSiegeInterruptedByEnemyDefection = true;
		}

		// Token: 0x06002434 RID: 9268 RVA: 0x000994B5 File Offset: 0x000976B5
		private void SetPlayerVictoriousInternal()
		{
			if (this.PlayerSide == BattleSideEnum.Attacker || this.PlayerSide == BattleSideEnum.Defender)
			{
				this._mapEvent.SetOverrideWinner(this.PlayerSide);
			}
		}

		// Token: 0x06002435 RID: 9269 RVA: 0x000994D9 File Offset: 0x000976D9
		public static void SetPlayerSiegeContinueWithDefenderPullBack()
		{
			PlayerEncounter.Current._mapEvent.SetDefenderPulledBack();
		}

		// Token: 0x06002436 RID: 9270 RVA: 0x000994EC File Offset: 0x000976EC
		private void DoApplyResults()
		{
			CampaignEventDispatcher.Instance.OnPlayerBattleEnd(this._mapEvent);
			this._mapEvent.ApplyBattleResults();
			if (this._mapEvent.WinningSide == PartyBase.MainParty.Side)
			{
				this.EncounterState = PlayerEncounterState.PlayerVictory;
				return;
			}
			if (this._mapEvent.DefeatedSide == PartyBase.MainParty.Side)
			{
				this.EncounterState = PlayerEncounterState.PlayerTotalDefeat;
				return;
			}
			this.EncounterState = PlayerEncounterState.End;
		}

		// Token: 0x06002437 RID: 9271 RVA: 0x0009955A File Offset: 0x0009775A
		public static void StartAttackMission()
		{
			PlayerEncounter.Current._campaignBattleResult = new CampaignBattleResult();
		}

		// Token: 0x06002438 RID: 9272 RVA: 0x0009956C File Offset: 0x0009776C
		private void DoPlayerVictory()
		{
			if (this._helpedHeroes == null)
			{
				this._helpedHeroes = new List<Hero>();
				foreach (PartyBase partyBase in MapEvent.PlayerMapEvent.InvolvedParties)
				{
					if (partyBase != PartyBase.MainParty && partyBase.Side == PartyBase.MainParty.Side && partyBase.Owner != null && partyBase.Owner != Hero.MainHero && partyBase.LeaderHero != null && (MapEvent.PlayerMapEvent.AttackerSide.LeaderParty == partyBase || MapEvent.PlayerMapEvent.DefenderSide.LeaderParty == partyBase) && partyBase.MobileParty != null && (partyBase.MobileParty.Army == null || partyBase.MobileParty.Army != MobileParty.MainParty.Army) && Campaign.Current.Models.BattleRewardModel.GetPlayerGainedRelationAmount(MapEvent.PlayerMapEvent, partyBase.LeaderHero) > 0)
					{
						this._helpedHeroes.Add(partyBase.LeaderHero);
					}
				}
				return;
			}
			if (this._helpedHeroes.Count > 0)
			{
				if (this._helpedHeroes[0].DeathMark == KillCharacterAction.KillCharacterActionDetail.None)
				{
					Campaign.Current.CurrentConversationContext = ConversationContext.PartyEncounter;
					ConversationCharacterData playerCharacterData = new ConversationCharacterData(CharacterObject.PlayerCharacter, PartyBase.MainParty, false, false, false, false, false, false);
					ConversationCharacterData conversationPartnerData = new ConversationCharacterData(this._helpedHeroes[0].CharacterObject, this._helpedHeroes[0].PartyBelongedTo.Party, false, false, false, false, false, false);
					CampaignMapConversation.OpenConversation(playerCharacterData, conversationPartnerData);
				}
				this._helpedHeroes.RemoveAt(0);
				this._stateHandled = true;
				return;
			}
			this.EncounterState = PlayerEncounterState.CaptureHeroes;
		}

		// Token: 0x06002439 RID: 9273 RVA: 0x00099738 File Offset: 0x00097938
		private void DoPlayerDefeat()
		{
			bool playerSurrender = PlayerEncounter.PlayerSurrender;
			PlayerEncounter.Finish(true);
			if (MobileParty.MainParty.BesiegerCamp != null)
			{
				if (MobileParty.MainParty.BesiegerCamp != null)
				{
					MobileParty.MainParty.BesiegerCamp = null;
				}
				else
				{
					PlayerSiege.ClosePlayerSiege();
				}
			}
			if (Hero.MainHero.DeathMark != KillCharacterAction.KillCharacterActionDetail.DiedInBattle)
			{
				GameMenu.ActivateGameMenu(playerSurrender ? "taken_prisoner" : "defeated_and_taken_prisoner");
			}
			this._stateHandled = true;
		}

		// Token: 0x0600243A RID: 9274 RVA: 0x000997A4 File Offset: 0x000979A4
		private void DoCaptureHeroes()
		{
			TroopRoster prisonerRosterReceivingLootShare = this._mapEvent.GetPrisonerRosterReceivingLootShare(PartyBase.MainParty);
			if (this._capturedHeroes == null)
			{
				this._capturedHeroes = prisonerRosterReceivingLootShare.RemoveIf((TroopRosterElement lordElement) => lordElement.Character.IsHero).ToList<TroopRosterElement>();
			}
			if (this._capturedHeroes.Count > 0)
			{
				TroopRosterElement troopRosterElement = this._capturedHeroes[this._capturedHeroes.Count - 1];
				Campaign.Current.CurrentConversationContext = ConversationContext.CapturedLord;
				ConversationCharacterData playerCharacterData = new ConversationCharacterData(CharacterObject.PlayerCharacter, PartyBase.MainParty, false, false, false, false, false, false);
				ConversationCharacterData conversationPartnerData = new ConversationCharacterData(troopRosterElement.Character, null, true, true, true, false, false, false);
				if (PlayerEncounter.InsideSettlement && Settlement.CurrentSettlement.IsHideout)
				{
					CampaignMission.OpenConversationMission(playerCharacterData, conversationPartnerData, "", "");
				}
				else
				{
					CampaignMapConversation.OpenConversation(playerCharacterData, conversationPartnerData);
				}
				Campaign.Current.ConversationManager.ConversationEndOneShot += delegate()
				{
					this._capturedHeroes.RemoveRange(this._capturedHeroes.Count - 1, 1);
				};
				this._stateHandled = true;
				return;
			}
			this.EncounterState = PlayerEncounterState.FreeHeroes;
		}

		// Token: 0x0600243B RID: 9275 RVA: 0x000998B4 File Offset: 0x00097AB4
		private void DoFreeHeroes()
		{
			TroopRoster memberRosterReceivingLootShare = this._mapEvent.GetMemberRosterReceivingLootShare(PartyBase.MainParty);
			if (this._freedHeroes == null)
			{
				this._freedHeroes = memberRosterReceivingLootShare.RemoveIf((TroopRosterElement lordElement) => lordElement.Character.IsHero).ToList<TroopRosterElement>();
			}
			if (this._freedHeroes.AnyQ((TroopRosterElement h) => h.Character.HeroObject.IsPrisoner))
			{
				TroopRosterElement troopRosterElement = this._freedHeroes.Last((TroopRosterElement h) => h.Character.HeroObject.IsPrisoner);
				Campaign.Current.CurrentConversationContext = ConversationContext.FreedHero;
				ConversationCharacterData playerCharacterData = new ConversationCharacterData(CharacterObject.PlayerCharacter, PartyBase.MainParty, false, false, false, false, false, false);
				ConversationCharacterData conversationPartnerData = new ConversationCharacterData(troopRosterElement.Character, null, true, true, false, false, false, false);
				CampaignMapConversation.OpenConversation(playerCharacterData, conversationPartnerData);
				this._stateHandled = true;
				return;
			}
			this.EncounterState = PlayerEncounterState.LootParty;
		}

		// Token: 0x0600243C RID: 9276 RVA: 0x000999AC File Offset: 0x00097BAC
		private void DoLootInventory()
		{
			ItemRoster itemRosterReceivingLootShare = this._mapEvent.GetItemRosterReceivingLootShare(PartyBase.MainParty);
			if (itemRosterReceivingLootShare.Count > 0)
			{
				InventoryManager.OpenScreenAsLoot(new Dictionary<PartyBase, ItemRoster>
				{
					{
						PartyBase.MainParty,
						itemRosterReceivingLootShare
					}
				});
				this._stateHandled = true;
			}
			this.EncounterState = PlayerEncounterState.End;
		}

		// Token: 0x0600243D RID: 9277 RVA: 0x000999F8 File Offset: 0x00097BF8
		private void DoLootParty()
		{
			TroopRoster memberRosterReceivingLootShare = this._mapEvent.GetMemberRosterReceivingLootShare(PartyBase.MainParty);
			TroopRoster prisonerRosterReceivingLootShare = this._mapEvent.GetPrisonerRosterReceivingLootShare(PartyBase.MainParty);
			if (memberRosterReceivingLootShare.Count > 0 || prisonerRosterReceivingLootShare.Count > 0)
			{
				PartyScreenManager.OpenScreenAsLoot(memberRosterReceivingLootShare, prisonerRosterReceivingLootShare, TextObject.Empty, memberRosterReceivingLootShare.TotalManCount + prisonerRosterReceivingLootShare.TotalManCount, null);
				this._stateHandled = true;
			}
			this.EncounterState = PlayerEncounterState.LootInventory;
		}

		// Token: 0x0600243E RID: 9278 RVA: 0x00099A62 File Offset: 0x00097C62
		public static void SacrificeTroops(int num, out TroopRoster losses, out ItemRoster lostBaggage)
		{
			PlayerEncounter.Current.SacrificeTroopsImp(num, out losses, out lostBaggage);
		}

		// Token: 0x0600243F RID: 9279 RVA: 0x00099A71 File Offset: 0x00097C71
		private void SacrificeTroopsImp(int num, out TroopRoster losses, out ItemRoster lostBaggage)
		{
			losses = new TroopRoster(null);
			lostBaggage = new ItemRoster();
			this._mapEvent.GetMapEventSide(this.PlayerSide).MakeReadyForSimulation(null, -1);
			this.RemoveRandomTroops(num, losses);
			this.RemoveRandomItems(lostBaggage);
		}

		// Token: 0x06002440 RID: 9280 RVA: 0x00099AAC File Offset: 0x00097CAC
		private void RemoveRandomItems(ItemRoster lostBaggage)
		{
			foreach (ItemRosterElement itemRosterElement in new ItemRoster(PartyBase.MainParty.ItemRoster))
			{
				if (!itemRosterElement.EquipmentElement.Item.NotMerchandise)
				{
					int num = MBRandom.RoundRandomized((float)itemRosterElement.Amount * 0.15f);
					PartyBase.MainParty.ItemRoster.AddToCounts(itemRosterElement.EquipmentElement, -num);
					lostBaggage.AddToCounts(itemRosterElement.EquipmentElement, num);
				}
			}
		}

		// Token: 0x06002441 RID: 9281 RVA: 0x00099B50 File Offset: 0x00097D50
		public void RemoveRandomTroops(int num, TroopRoster sacrifiedTroops)
		{
			int num2 = MobileParty.MainParty.Party.NumberOfRegularMembers;
			if (MobileParty.MainParty.Army != null)
			{
				foreach (MobileParty mobileParty in MobileParty.MainParty.Army.LeaderParty.AttachedParties)
				{
					num2 += mobileParty.Party.NumberOfRegularMembers;
				}
			}
			float sacrifaceRatio = (float)num / (float)num2;
			this.SacrifaceTroopsWithRatio(MobileParty.MainParty, sacrifaceRatio, sacrifiedTroops);
			if (MobileParty.MainParty.Army != null)
			{
				foreach (MobileParty mobileParty2 in MobileParty.MainParty.Army.LeaderParty.AttachedParties)
				{
					this.SacrifaceTroopsWithRatio(mobileParty2, sacrifaceRatio, sacrifiedTroops);
				}
			}
		}

		// Token: 0x06002442 RID: 9282 RVA: 0x00099C48 File Offset: 0x00097E48
		private void SacrifaceTroopsWithRatio(MobileParty mobileParty, float sacrifaceRatio, TroopRoster sacrifiedTroops)
		{
			int num = MBRandom.RoundRandomized((float)mobileParty.Party.NumberOfRegularMembers * sacrifaceRatio);
			for (int i = 0; i < num; i++)
			{
				float num2 = 100f;
				TroopRosterElement troopRosterElement = mobileParty.Party.MemberRoster.GetTroopRoster().FirstOrDefault<TroopRosterElement>();
				foreach (TroopRosterElement troopRosterElement2 in mobileParty.Party.MemberRoster.GetTroopRoster())
				{
					float num3 = (float)troopRosterElement2.Character.Level - ((troopRosterElement2.WoundedNumber > 0) ? 0.5f : 0f) - MBRandom.RandomFloat * 0.5f;
					if (!troopRosterElement2.Character.IsHero && num3 < num2 && troopRosterElement2.Number > 0)
					{
						num2 = num3;
						troopRosterElement = troopRosterElement2;
					}
				}
				mobileParty.MemberRoster.AddToCounts(troopRosterElement.Character, -1, false, (troopRosterElement.WoundedNumber > 0) ? -1 : 0, 0, true, -1);
				sacrifiedTroops.AddToCounts(troopRosterElement.Character, 1, false, 0, 0, true, -1);
			}
		}

		// Token: 0x06002443 RID: 9283 RVA: 0x00099D70 File Offset: 0x00097F70
		private void DoEnd()
		{
			MapEvent mapEvent = this._mapEvent;
			object obj = mapEvent != null && mapEvent.IsSiegeAssault;
			bool isHideoutBattle = this._mapEvent.IsHideoutBattle;
			object obj2 = obj;
			bool flag = obj2 != null && MobileParty.MainParty.MapEvent != null && MobileParty.MainParty.MapEvent == this._mapEvent;
			bool flag2 = MobileParty.MainParty.MapEvent != null && this.PlayerSide == BattleSideEnum.Attacker;
			bool isRaid = this._mapEvent.IsRaid;
			bool isForcingVolunteers = this._mapEvent.IsForcingVolunteers;
			bool isForcingSupplies = this._mapEvent.IsForcingSupplies;
			bool flag3 = this.BattleSimulation != null && this._mapEvent.WinningSide != this.PlayerSide;
			Settlement mapEventSettlement = this._mapEvent.MapEventSettlement;
			BattleState battleState = this._mapEvent.BattleState;
			this._stateHandled = true;
			if (!flag3)
			{
				PlayerEncounter.Finish(true);
			}
			else
			{
				PlayerEncounter.Battle.ResetBattleResults();
			}
			if (obj2 != null)
			{
				if (mapEventSettlement != null)
				{
					if (flag)
					{
						if (flag2)
						{
							EncounterManager.StartSettlementEncounter((MobileParty.MainParty.Army != null) ? MobileParty.MainParty.Army.LeaderParty : MobileParty.MainParty, mapEventSettlement);
							GameMenu.SwitchToMenu("menu_settlement_taken");
							return;
						}
					}
					else if (PlayerEncounter.InsideSettlement)
					{
						PlayerEncounter.LeaveSettlement();
						return;
					}
				}
			}
			else if (isRaid || isForcingVolunteers || isForcingSupplies)
			{
				if ((!this._attackerParty.IsMobile || this._attackerParty.MobileParty.Army == null || this._attackerParty.MobileParty.Army.LeaderParty == this._attackerParty.MobileParty) && flag2 && this._attackerParty == MobileParty.MainParty.Party)
				{
					EncounterManager.StartSettlementEncounter(MobileParty.MainParty, mapEventSettlement);
					PlayerEncounter.Current.ForceSupplies = isForcingSupplies;
					PlayerEncounter.Current.ForceVolunteers = isForcingVolunteers;
					PlayerEncounter.Current.ForceRaid = isRaid;
					BeHostileAction.ApplyEncounterHostileAction(PartyBase.MainParty, Settlement.CurrentSettlement.Party);
					if (isForcingSupplies)
					{
						GameMenu.SwitchToMenu("force_supplies_village");
						return;
					}
					if (isForcingVolunteers)
					{
						GameMenu.SwitchToMenu("force_volunteers_village");
						return;
					}
					if (isRaid)
					{
						if (PlayerEncounter.InsideSettlement)
						{
							LeaveSettlementAction.ApplyForParty(MobileParty.MainParty);
						}
						PlayerEncounter.StartBattle();
						GameMenu.SwitchToMenu("raiding_village");
						PlayerEncounter.Current.ForceRaid = false;
						PlayerEncounter.Current.ForceVolunteers = false;
						PlayerEncounter.Current.ForceSupplies = false;
						return;
					}
				}
			}
			else if (isHideoutBattle)
			{
				if (mapEventSettlement != null)
				{
					if (battleState == BattleState.AttackerVictory)
					{
						if (mapEventSettlement.Parties.Count > 0)
						{
							foreach (MobileParty mobileParty in new List<MobileParty>(mapEventSettlement.Parties))
							{
								LeaveSettlementAction.ApplyForParty(mobileParty);
								mobileParty.Ai.SetDoNotAttackMainParty(3);
							}
						}
						mapEventSettlement.Hideout.IsSpotted = false;
						mapEventSettlement.IsVisible = false;
						return;
					}
					if (battleState == BattleState.None)
					{
						EncounterManager.StartSettlementEncounter(MobileParty.MainParty, mapEventSettlement);
						GameMenu.SwitchToMenu("hideout_after_defeated_and_saved");
						return;
					}
				}
			}
			else if (flag3)
			{
				this.EncounterState = PlayerEncounterState.Begin;
				GameMenu.SwitchToMenu("encounter");
			}
		}

		// Token: 0x06002444 RID: 9284 RVA: 0x0009A084 File Offset: 0x00098284
		public bool CheckIfBattleShouldContinueAfterBattleMission()
		{
			if (this._doesBattleContinue || this._campaignBattleResult != null)
			{
				this._doesBattleContinue = this._mapEvent.CheckIfBattleShouldContinueAfterBattleMission(this._campaignBattleResult);
			}
			return this._doesBattleContinue;
		}

		// Token: 0x06002445 RID: 9285 RVA: 0x0009A0B4 File Offset: 0x000982B4
		public void FinalizeBattle()
		{
			if (this._mapEvent != null)
			{
				if (this._mapEvent.HasWinner || this._mapEvent.DiplomaticallyFinished || this._mapEvent.IsSiegeAmbush || (this._mapEvent.IsRaid && this._mapEvent.MapEventSettlement.SettlementHitPoints.ApproximatelyEqualsTo(0f, 1E-05f)))
				{
					MobileParty mobileParty = this._mapEvent.AttackerSide.LeaderParty.MobileParty;
					bool flag = this._mapEvent.IsRaid && this._mapEvent.BattleState == BattleState.AttackerVictory && !this._mapEvent.MapEventSettlement.SettlementHitPoints.ApproximatelyEqualsTo(0f, 1E-05f);
					Settlement mapEventSettlement = this._mapEvent.MapEventSettlement;
					this._mapEvent.FinalizeEvent();
					this._mapEvent = null;
					if (mobileParty != MobileParty.MainParty && flag)
					{
						mobileParty.Ai.SetMoveRaidSettlement(mapEventSettlement);
						mobileParty.Ai.RecalculateShortTermAi();
						return;
					}
				}
				else
				{
					PlayerEncounter.LeaveBattle();
				}
			}
		}

		// Token: 0x06002446 RID: 9286 RVA: 0x0009A1C8 File Offset: 0x000983C8
		public void FindNonAttachedNpcPartiesWhoWillJoinEvent(ref List<MobileParty> partiesToJoinPlayerSide, ref List<MobileParty> partiesToJoinEnemySide)
		{
			MapEvent mapEvent = this._mapEvent;
			LocatableSearchData<MobileParty> locatableSearchData = MobileParty.StartFindingLocatablesAroundPosition((mapEvent != null) ? mapEvent.Position : MobileParty.MainParty.Position2D, 4f);
			MobileParty mobileParty = MobileParty.FindNextLocatable(ref locatableSearchData);
			List<MobileParty> list = new List<MobileParty>();
			List<MobileParty> list2 = new List<MobileParty>();
			while (mobileParty != null)
			{
				if (mobileParty != MobileParty.MainParty && mobileParty.MapEvent == null && mobileParty.SiegeEvent == null && mobileParty.CurrentSettlement == null && mobileParty.AttachedTo == null && (mobileParty.IsLordParty || mobileParty.IsBandit || mobileParty.ShouldJoinPlayerBattles))
				{
					if (!mobileParty.MapFaction.IsAtWarWith(MobileParty.MainParty.MapFaction) && mobileParty.MapFaction.IsAtWarWith(PlayerEncounter.EncounteredParty.MapFaction))
					{
						list.Add(mobileParty);
					}
					if (mobileParty.MapFaction.IsAtWarWith(MobileParty.MainParty.MapFaction) && !mobileParty.MapFaction.IsAtWarWith(PlayerEncounter.EncounteredParty.MapFaction))
					{
						list2.Add(mobileParty);
					}
				}
				mobileParty = MobileParty.FindNextLocatable(ref locatableSearchData);
			}
			if (!list2.AnyQ((MobileParty t) => t.ShouldBeIgnored))
			{
				if (!partiesToJoinEnemySide.AnyQ((MobileParty t) => t.ShouldBeIgnored))
				{
					goto IL_171;
				}
			}
			Debug.Print("Ally parties wont join player encounter since there is an ignored party in enemy side", 0, Debug.DebugColor.White, 17592186044416UL);
			list.Clear();
			IL_171:
			if (!list.AnyQ((MobileParty t) => t.ShouldBeIgnored))
			{
				if (!partiesToJoinPlayerSide.AnyQ((MobileParty t) => t != MobileParty.MainParty && t.ShouldBeIgnored))
				{
					goto IL_1DC;
				}
			}
			Debug.Print("Enemy parties wont join player encounter since there is an ignored party in ally side", 0, Debug.DebugColor.White, 17592186044416UL);
			list2.Clear();
			IL_1DC:
			partiesToJoinPlayerSide.AddRange(list.Except(partiesToJoinPlayerSide));
			partiesToJoinEnemySide.AddRange(list2.Except(partiesToJoinEnemySide));
		}

		// Token: 0x06002447 RID: 9287 RVA: 0x0009A3D0 File Offset: 0x000985D0
		public void FindAllNpcPartiesWhoWillJoinEvent(ref List<MobileParty> partiesToJoinPlayerSide, ref List<MobileParty> partiesToJoinEnemySide)
		{
			this.FindNonAttachedNpcPartiesWhoWillJoinEvent(ref partiesToJoinPlayerSide, ref partiesToJoinEnemySide);
			foreach (MobileParty mobileParty in partiesToJoinPlayerSide.ToList<MobileParty>())
			{
				partiesToJoinPlayerSide.AddRange(mobileParty.AttachedParties.Except(partiesToJoinPlayerSide));
			}
			foreach (MobileParty mobileParty2 in partiesToJoinEnemySide.ToList<MobileParty>())
			{
				partiesToJoinEnemySide.AddRange(mobileParty2.AttachedParties.Except(partiesToJoinEnemySide));
			}
		}

		// Token: 0x06002448 RID: 9288 RVA: 0x0009A48C File Offset: 0x0009868C
		public static void EnterSettlement()
		{
			Settlement encounterSettlement = PlayerEncounter.EncounterSettlement;
			PlayerEncounter.CreateLocationEncounter(encounterSettlement);
			EnterSettlementAction.ApplyForParty(MobileParty.MainParty, encounterSettlement);
		}

		// Token: 0x06002449 RID: 9289 RVA: 0x0009A4B0 File Offset: 0x000986B0
		private static void CreateLocationEncounter(Settlement settlement)
		{
			if (settlement.IsTown)
			{
				PlayerEncounter.LocationEncounter = new TownEncounter(settlement);
				return;
			}
			if (settlement.IsVillage)
			{
				PlayerEncounter.LocationEncounter = new VillageEncounter(settlement);
				return;
			}
			if (settlement.IsCastle)
			{
				PlayerEncounter.LocationEncounter = new CastleEncounter(settlement);
			}
		}

		// Token: 0x0600244A RID: 9290 RVA: 0x0009A4F0 File Offset: 0x000986F0
		public static void LeaveBattle()
		{
			MapEvent playerMapEvent = MapEvent.PlayerMapEvent;
			bool flag = false;
			if (playerMapEvent != null)
			{
				int numberOfInvolvedMen = playerMapEvent.GetNumberOfInvolvedMen(PartyBase.MainParty.Side);
				Army playerArmy = MobileParty.MainParty.Army;
				if ((PartyBase.MainParty.MapEventSide.LeaderParty != PartyBase.MainParty && PartyBase.MainParty.MapEventSide.Parties.Any(delegate(MapEventParty p)
				{
					if (!p.IsNpcParty)
					{
						return false;
					}
					if (playerArmy != null)
					{
						MobileParty mobileParty = p.Party.MobileParty;
						return ((mobileParty != null) ? mobileParty.Army : null) != playerArmy;
					}
					return true;
				})) || (PartyBase.MainParty.MapEvent.IsSallyOut && Campaign.Current.Models.EncounterModel.GetLeaderOfMapEvent(PartyBase.MainParty.MapEvent, PartyBase.MainParty.MapEventSide.MissionSide) != Hero.MainHero))
				{
					PartyBase.MainParty.MapEventSide = null;
				}
				else
				{
					playerMapEvent.FinalizeEvent();
				}
				flag = (numberOfInvolvedMen > PartyBase.MainParty.NumberOfHealthyMembers && playerMapEvent.AttackerSide.LeaderParty != PartyBase.MainParty && playerMapEvent.DefenderSide.LeaderParty != PartyBase.MainParty);
			}
			if (PlayerEncounter.CurrentBattleSimulation != null)
			{
				MapState mapState = Game.Current.GameStateManager.LastOrDefault<MapState>();
				if (mapState != null && mapState.IsSimulationActive)
				{
					mapState.EndBattleSimulation();
				}
				PlayerEncounter.Current.BattleSimulation = null;
				PlayerEncounter.Current._mapEvent.BattleObserver = null;
			}
			PlayerEncounter.Current.IsJoinedBattle = false;
			PlayerEncounter.Current._mapEvent = null;
			if (flag && !playerMapEvent.HasWinner)
			{
				MapEvent mapEvent = playerMapEvent;
				BattleSimulation battleSimulation = PlayerEncounter.Current.BattleSimulation;
				mapEvent.SimulateBattleSetup((battleSimulation != null) ? battleSimulation.SelectedTroops : null);
			}
		}

		// Token: 0x0600244B RID: 9291 RVA: 0x0009A678 File Offset: 0x00098878
		public static void LeaveSettlement()
		{
			LeaveSettlementAction.ApplyForParty(MobileParty.MainParty);
			PlayerEncounter.LocationEncounter = null;
			PartyBase.MainParty.SetVisualAsDirty();
		}

		// Token: 0x0600244C RID: 9292 RVA: 0x0009A694 File Offset: 0x00098894
		public static void InitSimulation(FlattenedTroopRoster selectedTroopsForPlayerSide, FlattenedTroopRoster selectedTroopsForOtherSide)
		{
			if (PlayerEncounter.Current == null)
			{
				return;
			}
			PlayerEncounter.Current.BattleSimulation = new BattleSimulation(selectedTroopsForPlayerSide, selectedTroopsForOtherSide);
		}

		// Token: 0x0600244D RID: 9293 RVA: 0x0009A6AF File Offset: 0x000988AF
		public void InterruptEncounter(string encounterInterrupedType)
		{
			GameState activeState = Game.Current.GameStateManager.ActiveState;
			if (MapEvent.PlayerMapEvent != null)
			{
				PlayerEncounter.LeaveBattle();
			}
			GameMenu.ActivateGameMenu(encounterInterrupedType);
		}

		// Token: 0x0600244E RID: 9294 RVA: 0x0009A6D4 File Offset: 0x000988D4
		public static void StartSiegeAmbushMission()
		{
			Settlement mapEventSettlement = PlayerEncounter.Battle.MapEventSettlement;
			SiegeEvent playerSiegeEvent = PlayerSiege.PlayerSiegeEvent;
			Settlement.SiegeState currentSiegeState = mapEventSettlement.CurrentSiegeState;
			if (currentSiegeState == Settlement.SiegeState.OnTheWalls)
			{
				List<MissionSiegeWeapon> preparedAndActiveSiegeEngines = playerSiegeEvent.GetPreparedAndActiveSiegeEngines(playerSiegeEvent.GetSiegeEventSide(BattleSideEnum.Attacker));
				List<MissionSiegeWeapon> preparedAndActiveSiegeEngines2 = playerSiegeEvent.GetPreparedAndActiveSiegeEngines(playerSiegeEvent.GetSiegeEventSide(BattleSideEnum.Defender));
				bool hasAnySiegeTower = preparedAndActiveSiegeEngines.Exists((MissionSiegeWeapon data) => data.Type == DefaultSiegeEngineTypes.SiegeTower);
				int wallLevel = mapEventSettlement.Town.GetWallLevel();
				CampaignMission.OpenSiegeMissionWithDeployment(mapEventSettlement.LocationComplex.GetLocationWithId("center").GetSceneName(wallLevel), mapEventSettlement.SettlementWallSectionHitPointsRatioList.ToArray(), hasAnySiegeTower, preparedAndActiveSiegeEngines, preparedAndActiveSiegeEngines2, PlayerEncounter.Current.PlayerSide == BattleSideEnum.Attacker, wallLevel, true, false);
				return;
			}
			if (currentSiegeState - Settlement.SiegeState.InTheLordsHall > 1)
			{
				return;
			}
			Debug.FailedAssert("Siege state is invalid!", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\Encounters\\PlayerEncounter.cs", "StartSiegeAmbushMission", 2223);
		}

		// Token: 0x0600244F RID: 9295 RVA: 0x0009A7B0 File Offset: 0x000989B0
		public static void StartVillageBattleMission()
		{
			Settlement mapEventSettlement = PlayerEncounter.Battle.MapEventSettlement;
			int upgradeLevel = mapEventSettlement.IsTown ? mapEventSettlement.Town.GetWallLevel() : 1;
			CampaignMission.OpenBattleMission(mapEventSettlement.LocationComplex.GetScene("village_center", upgradeLevel), true);
		}

		// Token: 0x06002450 RID: 9296 RVA: 0x0009A7F8 File Offset: 0x000989F8
		public static void StartCombatMissionWithDialogueInTownCenter(CharacterObject characterToTalkTo)
		{
			int wallLevel = Settlement.CurrentSettlement.Town.GetWallLevel();
			CampaignMission.OpenCombatMissionWithDialogue(Settlement.CurrentSettlement.LocationComplex.GetScene("center", wallLevel), characterToTalkTo, wallLevel);
		}

		// Token: 0x06002451 RID: 9297 RVA: 0x0009A832 File Offset: 0x00098A32
		public static void StartHostileAction()
		{
			PlayerEncounter.Current.StartHostileActionInternal();
		}

		// Token: 0x06002452 RID: 9298 RVA: 0x0009A83E File Offset: 0x00098A3E
		private void StartHostileActionInternal()
		{
			if (this._mapEvent != null)
			{
				if (PlayerEncounter.InsideSettlement)
				{
					PlayerEncounter.LeaveSettlement();
				}
				PlayerEncounter.Update();
			}
		}

		// Token: 0x06002453 RID: 9299 RVA: 0x0009A85C File Offset: 0x00098A5C
		public void FinishRaid()
		{
			bool diplomaticallyFinished = PlayerEncounter.Battle.DiplomaticallyFinished;
			PartyBase leaderParty = PlayerEncounter.Battle.AttackerSide.LeaderParty;
			PlayerEncounter.Finish(true);
			if (!diplomaticallyFinished)
			{
				if (leaderParty == MobileParty.MainParty.Party)
				{
					GameMenu.ActivateGameMenu("village_player_raid_ended");
					return;
				}
				GameMenu.ActivateGameMenu("village_raid_ended_leaded_by_someone_else");
			}
		}

		// Token: 0x06002454 RID: 9300 RVA: 0x0009A8B0 File Offset: 0x00098AB0
		public static void GetBattleRewards(out float renownChange, out float influenceChange, out float moraleChange, out float goldChange, out float playerEarnedLootPercentage, ref ExplainedNumber renownExplainedNumber, ref ExplainedNumber influenceExplainedNumber, ref ExplainedNumber moraleExplainedNumber)
		{
			if (PlayerEncounter.Current == null)
			{
				renownChange = 0f;
				influenceChange = 0f;
				moraleChange = 0f;
				goldChange = 0f;
				playerEarnedLootPercentage = 0f;
				return;
			}
			PlayerEncounter.Current.GetBattleRewardsInternal(out renownChange, out influenceChange, out moraleChange, out goldChange, out playerEarnedLootPercentage, ref renownExplainedNumber, ref influenceExplainedNumber, ref moraleExplainedNumber);
		}

		// Token: 0x06002455 RID: 9301 RVA: 0x0009A900 File Offset: 0x00098B00
		private void GetBattleRewardsInternal(out float renownChange, out float influenceChange, out float moraleChange, out float goldChange, out float playerEarnedLootPercentage, ref ExplainedNumber renownExplainedNumber, ref ExplainedNumber influenceExplainedNumber, ref ExplainedNumber moraleExplainedNumber)
		{
			MapEventResultExplainer battleResultExplainers = this._mapEvent.BattleResultExplainers;
			this._mapEvent.GetBattleRewards(PartyBase.MainParty, out renownChange, out influenceChange, out moraleChange, out goldChange, out playerEarnedLootPercentage);
			if (battleResultExplainers != null)
			{
				renownExplainedNumber = battleResultExplainers.RenownExplainedNumber;
				influenceExplainedNumber = battleResultExplainers.InfluenceExplainedNumber;
				moraleExplainedNumber = battleResultExplainers.MoraleExplainedNumber;
			}
		}

		// Token: 0x06002456 RID: 9302 RVA: 0x0009A95C File Offset: 0x00098B5C
		public float GetPlayerStrengthRatioInEncounter()
		{
			List<MobileParty> list = new List<MobileParty>
			{
				MobileParty.MainParty
			};
			List<MobileParty> list2 = new List<MobileParty>
			{
				MobileParty.ConversationParty
			};
			this.FindAllNpcPartiesWhoWillJoinEvent(ref list, ref list2);
			float num = 0f;
			float num2 = 0f;
			foreach (MobileParty mobileParty in list)
			{
				if (mobileParty != null)
				{
					num += mobileParty.Party.TotalStrength;
				}
				else
				{
					Debug.FailedAssert("Player side party null", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\Encounters\\PlayerEncounter.cs", "GetPlayerStrengthRatioInEncounter", 2332);
				}
			}
			foreach (MobileParty mobileParty2 in list2)
			{
				if (mobileParty2 != null)
				{
					num2 += mobileParty2.Party.TotalStrength;
				}
				else
				{
					Debug.FailedAssert("Opponent side party null", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\Encounters\\PlayerEncounter.cs", "GetPlayerStrengthRatioInEncounter", 2344);
				}
			}
			if (num2 <= 0f)
			{
				num2 = 1E-05f;
			}
			return num / num2;
		}

		// Token: 0x04000AD8 RID: 2776
		[SaveableField(0)]
		public static bool EncounteredPartySurrendered;

		// Token: 0x04000AD9 RID: 2777
		[SaveableField(1)]
		public bool FirstInit = true;

		// Token: 0x04000ADA RID: 2778
		public const float JoiningRadius = 3f;

		// Token: 0x04000ADD RID: 2781
		[SaveableField(5)]
		public bool IsEnemy;

		// Token: 0x04000ADF RID: 2783
		[SaveableField(7)]
		public float PlayerPartyInitialStrength;

		// Token: 0x04000AE0 RID: 2784
		[SaveableField(8)]
		private CampaignBattleResult _campaignBattleResult;

		// Token: 0x04000AE1 RID: 2785
		[SaveableField(9)]
		public float PartiesStrengthRatioBeforePlayerJoin;

		// Token: 0x04000AE2 RID: 2786
		[SaveableField(10)]
		public bool ForceRaid;

		// Token: 0x04000AE3 RID: 2787
		[SaveableField(11)]
		public bool ForceSallyOut;

		// Token: 0x04000AE4 RID: 2788
		[SaveableField(32)]
		public bool ForceVolunteers;

		// Token: 0x04000AE5 RID: 2789
		[SaveableField(33)]
		public bool ForceSupplies;

		// Token: 0x04000AE6 RID: 2790
		[SaveableField(34)]
		private bool _isSiegeInterruptedByEnemyDefection;

		// Token: 0x04000AE7 RID: 2791
		public BattleSimulation BattleSimulation;

		// Token: 0x04000AE8 RID: 2792
		[SaveableField(13)]
		private MapEvent _mapEvent;

		// Token: 0x04000AE9 RID: 2793
		[SaveableField(14)]
		private PlayerEncounterState _mapEventState;

		// Token: 0x04000AEA RID: 2794
		[SaveableField(15)]
		private PartyBase _encounteredParty;

		// Token: 0x04000AEB RID: 2795
		[SaveableField(16)]
		private PartyBase _attackerParty;

		// Token: 0x04000AEC RID: 2796
		[SaveableField(17)]
		private PartyBase _defenderParty;

		// Token: 0x04000AED RID: 2797
		[SaveableField(18)]
		private List<Hero> _helpedHeroes;

		// Token: 0x04000AEE RID: 2798
		[SaveableField(19)]
		private List<TroopRosterElement> _capturedHeroes;

		// Token: 0x04000AEF RID: 2799
		[SaveableField(20)]
		private List<TroopRosterElement> _freedHeroes;

		// Token: 0x04000AF0 RID: 2800
		[SaveableField(22)]
		private bool _leaveEncounter;

		// Token: 0x04000AF1 RID: 2801
		[SaveableField(23)]
		private bool _playerSurrender;

		// Token: 0x04000AF2 RID: 2802
		[SaveableField(24)]
		private bool _enemySurrender;

		// Token: 0x04000AF3 RID: 2803
		[SaveableField(25)]
		private bool _battleChallenge;

		// Token: 0x04000AF4 RID: 2804
		[SaveableField(26)]
		private bool _meetingDone;

		// Token: 0x04000AF5 RID: 2805
		[SaveableField(27)]
		private bool _stateHandled;

		// Token: 0x04000AF6 RID: 2806
		[SaveableField(36)]
		private ItemRoster _alternativeRosterToReceiveLootItems;

		// Token: 0x04000AF7 RID: 2807
		[SaveableField(37)]
		private TroopRoster _alternativeRosterToReceiveLootPrisoners;

		// Token: 0x04000AF8 RID: 2808
		[SaveableField(38)]
		private TroopRoster _alternativeRosterToReceiveLootMembers;

		// Token: 0x04000AFB RID: 2811
		[SaveableField(51)]
		private bool _doesBattleContinue;

		// Token: 0x04000AFC RID: 2812
		[SaveableField(52)]
		private bool _isSallyOutAmbush;
	}
}
